for Windows & Linux containers
I assume that you might have already heard that “Docker Desktop” is only free for personal and small business use because of the licensing changes .
If you’re working for a big company or using it for commercial use, you have to pay the license cost.
Honestly, Docker desktop is a great tool. If your company is ready to pay for the license, that’s well and good. You’re lucky. Go for it.
Because, we have a lot of amazing features in Docker desktop without worrying about doing any manual configurations.
If you decided not to pay the license for docker desktop at wrok, you are supposed to uninstall the Docker Desktop.
The fact that you will be losing a few amazing UI features when uninstalling docker desktop.
However, you have alternate ways to make it work without docker desktop. No worries!!
It’s easy!. Let me cover the process of setting up docker without docker desktop for both windows and Linux in this article.
Essentially, we don’t need docker desktop at all if we take down the path to use only the Docker Daemon & CLIs.
Let’s start with the Windows container.
Windows Container
It can be done in 2 different ways.
- Manually making changes in Windows features in the system, then downloading docker, installing
- Using the PowerShell Commands as admin.
I am going to use the PowerShell Commands in this article.
Open the PowerShell Terminal as admin and run the following instruction.
Enable Hyper-V :
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All
Enable Containers :
Enable-WindowsOptionalFeature -Online -FeatureName containers –All
Download the Docker.zip and set the PATH:
curl.exe -o docker.zip -LO https://download.docker.com/win/static/stable/x86_64/docker-20.10.13.zip
Expand-Archive docker.zip -DestinationPath C:\
[Environment]::SetEnvironmentVariable(“Path”, “$($env:path);C:\docker”, [System.EnvironmentVariableTarget]::Machine)
$env:Path = [System.Environment]::GetEnvironmentVariable(“Path”,”Machine”)
Register Docker Daemon as service:
dockerd — register-service
Start the service:
Start-Service docker
Run the “hello-world” container.
docker run hello-world
The message from docker will display as “Hello from Docker!”
Windows Container is all set now.
Now, moving on to the Linux container.
Linux Containers
With a docker Desktop, it was fairly easy for switching Containers from running Windows to Linux and vice versa.
Find the docker whale in the system tray and use the “Switch to Linux Containers” option.
After uninstalling the docker desktop, that’s not possible. Need to set up the WSL(Windows SubSystem for Linux).
To start with, install WSL2 to run the Docker Daemon for Linux containers.
During that process, you need to prepare one of the Linux distribution of your choice (Ubuntu, Debian, Alpine, Fedora) in WSL2.
I am going with the default Linux distribution (Ubuntu) in this article.
Installing WSL2
You can refer to this microsoft article to install WSL.
Few key points to note during the process.
WSL installation:
In PowerShell, use
> wsl — install
This command will enable the features necessary to run WSL and install the Ubuntu distribution of Linux
Please note that these steps require WSL 2 (not version 1).
Why WSL2?
WSL 2 uses an actual Linux kernel that allows Linux containers. WSL 1 was genius with running Linux on the Windows kernel, but of course lacked some of the features, such as containers.
Microsoft offers a more detailed comparison in the docs.
Check which version of WSL you are running
In PowerShell or Windows Command Prompt.
wsl -l -v
Install a Linux distro
If you do not yet have a running WSL instance with a distro of your choice, the next step is to pick one from the Microsoft Store.
If you dislike the Windows Store, there are other options for downloading distro.
Like I mentioned earlier, I am going with default ubuntu distro in this article.
Set up your Linux user info
Once you have installed WSL, you will need to create a user account and password for your newly installed Linux distribution.
See the Best practices for setting up a WSL development environment guide to learn more.
Use Windows Terminal (Optional)
I recommend using the windows terminal to run further commands to explore the Ubuntu distro.
Download the windows terminal from Microsoft store.
After installing, you can start the windows terminal and open the ubuntu distro.
Turn on Systemd:
This change means that WSL will be even more similar to using your favorite Linux distros on a bare metal machine, and will let you use software that depends on systemd support.
To set the systemd flag set in your WSL distro settings, you will need to edit the wsl.conf file to ensure systemd starts up on boot.
Add these lines to the /etc/wsl.conf (note you will need to run your editor with sudo privileges, e.g: sudo nano /etc/wsl.conf):
[boot]
systemd=true
And close out of the nano editor using CTRL+O to save and CTRL+X to exit.
Verify the Systemd:
With the above steps done, close your WSL distro Windows and run wsl.exe — shutdown from PowerShell to restart your WSL instances.
Upon launch you should have systemd running. You can check this with the command which should show your services’ status.
systemctl list-unit-files — type=service
Update/upgrade packages in Linux distro
Let’s make everything new and shiny in the ubuntu with the following command
sudo apt update && sudo apt upgrade
Prepare for Docker installation
Remove residue (Optional)
If this is not a fresh install, and you may have experimented with docker before, then first clear out any residual docker installs:
sudo apt remove docker docker-engine docker.io containerd runc
Install docker using APT Repository
There is an official guide for installing Docker on ubuntu Linux distribution
Follow the Install using the apt repository section
Add user to docker group
The Docker daemon is a service that Docker requires to be running in the background. The service (dockerd) and client (docker) communicate over a socket and/or a network port.
For communication over the socket, privileged access is required.
Two ways to obtain this access:
- Run docker as root (i.e. sudo docker)
- Through group membership, grant specific users privileged access to the Docker socket
In other words, unless you want to utilize sudo or root access every time, add your user to the Docker group, named docker:
sudo usermod -aG docker $USER
Then close that WSL window, and launch WSL again.
You can do it through PowerShell too.
wsl — shutdown
This will kill Linux. You can start the wsl in new window by typing wsl
You should see docker when you run the command groups to list group memberships.
Options for Running docker from Windows
Windows Terminal:
If configured as above, I recommend always running docker from wsl.
You can run the container from the WSL window.
VSCode supports docker in WSL 2:
https://code.visualstudio.com/blogs/2020/07/01/containers-wsl
In short , the command “Code . .” will open up the visual studio code.
You can see that your windows machine folders are mounted in ubuntu. You can notice the directory starts with /mnt/c/Users/<username>.
You can change the directory to your desired folder and start your docker commands.
Ex:
cd /mnt/c/PROJECTS/<project folder>/src
Refer the setting VS code as editor.
To learn more about the file storage, Refer File storage in WSL
You’re all set!
Thank you, Happy Coding!