The manual is used to prepare an environment for the containerization training cycle at Future Processing.
All commands should be run in shell with administrator privileges. PowerShell was used to run the commands
Microsoft simplified installation of WSL2 starting with Windows 10 version 2004 (see documentation for details).
- Open PowerShell terminal
- Install Ubuntu 20.04 LTS distribution
wsl --install --distribution Ubuntu-20.04
- Reboot
- Enter new UNIX username and password (new user will be created in Linux)
- Enjoy new Linux instance
Important: To start the Docker service automatically follow the "Run Docker when a WSL instance launches" section after successful installation
Choose and execute one of the available installation methods: scripted or manually.
- Open PowerShell terminal
- Download setup.sh script
Invoke-WebRequest -uri https://raw.githubusercontent.com/FutureProcessing/Docker-WSL2/master/setup.sh -OutFile setup.sh
- Execute the script
Expected output:
wsl -- ./setup.sh
Docker Server version is xx.xx.xx
- Stop WSL session
logout
- Start WSL session
wsl
- Enjoy Docker Engine
- Start WSL session
wsl
- Download PGP Public Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --quiet --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
- Add APT source list
echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
- Update APT package information
sudo apt update --yes
- Install Docker Community Edition
sudo apt install --yes docker-ce
- Add current user do the
docker
groupNote: For the new group to be used by your system, it is necessary to log outsudo usermod -aG docker $(whoami)
- Stop WSL session
logout
- Start WSL session
wsl
- Start Docker service
sudo service docker start
- Check server version
Expected output:
docker info --format "Docker Server version is {{.ServerVersion}}"
Docker Server version: xx.xx.xx
By default operating system running in WSL does not start services
automatically so Docker service is not running after reboot. One could execute
sudo service docker start
command each time or automate that action using
following instruction.
If you have installed Windows 11, you can start docker using the Boot setting (link).
In WSL instance edit file /etc/wsl.conf
and add the following content (file is
also accessible via \\wsl$\<distro-name>\etc\wsl.conf
)
[boot]
command = service docker start
More information available here.
In previous versions of Windows you can use .profile
file to automatically start the service if it's not running.
Add the following line to ~/.profile
file (\\wsl$\<distro-name>\home\<username>\.profile
) or any shell configuration file you're using (i.e. .bash_profile
).
(sudo service docker status || sudo service docker start) > /dev/null
In ubuntu 20.10* due to incompatibility of Docker Engine with nftables, legacy iptables should be used. To switch default iptables execute the following command and choose iptables-legacy
sudo update-alternatives --config iptables
Download, install and run Visual Studio Code
https://code.visualstudio.com/Download
- Install Remote WSL extension.
(Pressctrl+p
and executeext install ms-vscode-remote.remote-wsl
) - In the bottom left corner, press the green button
- Select
Remote WSL: New Window
- Download and install Windows Terminal
https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701 - Open Windows Terminal and select Ubuntu
-
In Ubuntu execute following command
docker run -d -p 80:80 docker/getting-started
Expected output example
Unable to find image 'docker/getting-started:latest' locally latest: Pulling from docker/getting-started aad63a933944: Pull complete b14da7a62044: Pull complete 343784d40d66: Pull complete 6f617e610986: Pull complete Digest: sha256:d2c4fb0641519ea208f20ab03dc40ec2a5a53fdfbccca90bef14f870158ed577 Status: Downloaded newer image for docker/getting-started:latest ad77e95c178b1bdd3c752b45223e40b2f9a964a99cd6ee611043805518631d42
Docker Compose is available as part of docker-compose-plugin
package installed
as dependency to docker-ce
package.
Docker Compose should be used as docker compose
command. Command
docker-compose
is deprecated.
Conflict with Docker Desktop. Docker Desktop may try to change the configuration of the WSL distribution if it is the default.