Setup the VM and install the Docker Daemon
Install the Virtual Box and make sure you have it installed Host Only Network Adapter.
After setup, download it CentOS Minimal ISO and create a VM by installing CentOS. Make sure the RAM is not less than 2048MB. It is also best to create a user on your machine and avoid using it root account. Use the same USERNAME as WSL USERNAME. This is not absolutely necessary, but it is useful for avoiding future mistakes. After installation is complete make sure it can connect to Internet and turn it off.
Now, go to your newly created VM settings, let's take an example called Containers. In the area Networking, turn on the 2 Adapter and connect it to Host Only Network Adapter. Turn on the system.
Turn on the machine. You have to discover the young adapters IP, which you will use later. To do this, we will need it ifconfig command found by them net-tools. Execute the following commands:
sudo yum -y install net-tools
The second command will result in something similar to the following.
Make sure you note it somewhere IP.
Time to install Docker. Here are the commands from the Docker Documents, which we recommend you read.
sudo yum install -y yum-utils \
sudo yum-config-manager \
sudo yum install docker-ce docker-ce-cli containerd.io
Docker is now installed, you can enable it.
sudo systemctl enable docker
And now, make sure it runs with
sudo systemctl status docker
Finally, add the user to docker group. Note: If you use a different username in WSL, add it instead of $ USER.
sudo usermod -a -G docker $ USER
Configure Docker CLI in WSL to control Docker from Windows.
Now, exit the VM and load it WSL. Install them Docker's dependencies, add it pgp key and add the constant repository for Ubuntu.
sudo apt-get install -y \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
«Deb [arch = amd64] https://download.docker.com/linux/ubuntu \
$ (lsb_release -cs) \
Now update your system and install the latest one
sudo apt-get update -y
sudo apt-get install -y docker-ce
Install Docker Compose using PIP (with instructions if you don't already have one)
sudo apt-get install -y python python-pip
pip install –user docker-compose
Make sure the volume setting functions are working.
For this, you need to edit them volume mounts to make sure everything works. This requires you to have them Windows 10 1803 or later.
Add the following 3 lines to /etc/wsl.conf with a word processor of your choice. I use VIM.
root = /
options = "metadata"
You will need to restart in order for these changes to take effect.
You must guide WSL to use it VM's Docker Host. Remember the IP for Host Only Network Adapter by replacing it (VMIP) and the VM username below (VMUN).
echo «export DOCKER_HOST = ssh: // <VMUN> @ <VMIP>: 2375» >> ~ / .bashrc
source ~ / .Bashrc
It's time to get started! Run docker information and you're reasonably prepared.
You will be prompted for your VM password and then the result will be returned.
SSH Keys Configuration
Obviously it's very tiring to set up SSH Keys every time we run a command, so we can configure SSH Keys to avoid it.
Create an RSA SSH Key in WSL
ssh-keygen -t rsa
Create the ssh folder in your VM
ssh <VMUN> @ <VMIP> mkdir -p .ssh
Add the SSH key to the Authorized Keys of the VM
cat .ssh / id_rsa.pub | ssh <VMUN> @ <VMIP> 'cat >> .ssh / authorized_keys'
Define permissions in the VM's .ssh directory
ssh <VMUN> @ <VMIP> «chmod 700 .ssh; chmod 640 .ssh / authorized_keys »
Now, Docker, as well as any other sessions through SSH, will work without requiring a password.
Editing the Hosts file
Edit it file Hosts on the local Windows machine. Add the following two lines (the first is a comment) to the hosts file located at C: \ Windows \ System32 \ drivers \ etc. Remember to replace IP with yours.
We hope to help you with our guide.
How useful was this post?
Average rating / 5. Vote count: