Installing docker in Windows 10 wsl1

Time:2020-7-31

A recent attempt was made to install Ubuntu using a virtual machine, and then install the docker deployment service in Ubuntu. Looking at the official installation document of docker, we found that we can use wsl2 to install docker on Windows 10. Start to try to install the configuration, the results found that wsl2 can only be used on the preview version of windows 10 system. Preview version, right? Upgrade!!! Then, after upgrading, my computer card exploded, and I still couldn’t connect to WiFi, so I had to restore the previous version. But ubuunt is already installed, so WSL + docker for windows is the second best choice

Install Linux subsystem

Open window settings – select Update and install – select developer options – change to developer modeInstalling docker in Windows 10 wsl1

Windows – start or close windows functions – check the windows subsystem for LinuxInstalling docker in Windows 10 wsl1

Open windows store – search for Ubuntu 18.04 installation
Installing docker in Windows 10 wsl1
Open the installed Ubuntu and set the user name and login password

Common settings of Ubuntu

Ubuntu install docker

Official website guidance

Install docker for windows

The architecture design of docker is divided into three components: a client, a rest API and a server (daemons)

  • Client: interact with rest API. The main purpose is to allow users to connect to the daemons.
  • Rest API: act as the interface between client and server to realize communication.
  • Daemons: responsible for the actual management of the container – start, stop, etc. The daemons listen for API requests from docker clients

Unfortunately, WSL does not support docker daemons at present, but you can use the docker cli to connect to remote docker daemons running through docker for windows or any other VM you create

So now when you execute the docker command in Ubuntu, the following error message appears

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

I solved this problem by installing docker for windows
Download address

Configure docker for windows
In general settings, you need to expose daemons that do not have TLS. This step is necessary for the daemons to listen on TCP endpoints. If you don’t, you won’t be able to connect from WSL.

So in order for the client to communicate with the docker, the following options must be turned on
Installing docker in Windows 10 wsl1

You may also want to share your drive (local: drive letter). This step is not necessary, but if you need a file with a certain drive letter, it is recommended to check the corresponding option, go to the “shared drives” setting and enable it.

Configure WSL

Configure WSL to connect to docker for windows
export DOCKER\_HOST=tcp://127.0.0.1:2375

Installing docker in Windows 10 wsl1
However, this environment variable only lasts until the end of the session. Bash must be reset every time you open it. Therefore, to avoid this, you need a. Bash in your home directory_ Set the variable in the file of profile or. Bashrc,

Open the one of the two files that has data and add it at the end
Installing docker in Windows 10 wsl1

After saving, restart the bash console to execute docker related commands, which can be executed as usual