简体   繁体   中英

Running docker on Ubuntu 18.04.2 LTS

As announced by Microsoft blog , docker is supported on WSL2 now. I am trying to install docker on Linux Subsystem for Windows10. After following all the steps mentioned in this official documentation I am getting following error.

$docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
$ docker version
Client: Docker Engine - Community
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        74b1e89
 Built:             Thu Jul 25 21:21:05 2019
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Am I missing anything here?

Docker is now supported on WSL2

Pre-requisite for running docker successfully on WSL2

  1. Windows 10 (Build 18932 or higher). To check the OS Build version Win-Key + R, run command "winver"
  2. You can get the Build#18932 by registering for windows insider program and then check latest windows updates on your machine
  3. Enable WSL on your machine( Windows10 ) and then run wsl --set-default-version 2 with admin on Powershell command to always use WSL2 on your machine

Now you are ready to install Linux distro on your machine. Install Ubuntu on Windows 10 WSL using these instructions

you need to start the docker explicitly with sudo /etc/init.d/docker start

To verify everything is fine after installation; run the following command on Powershell. If it shows below output, that means Ubuntu-18.04 is running on WSL 2

PS> wsl -l -v
 NAME            STATE           VERSION
* Ubuntu-18.04    Running         2

-reference: microsoft/wsl on Github

You cant run the docker daemon inside of WSL, which means you cant host containers inside of WSL. But you can connect to the daemon running on windows using the docker client running inside of WSL.

Firstly you need to get docker desktop for windows https://docs.docker.com/docker-for-windows/install/

When you have done this do ensure that the setting to expose daemon on tcp://localhost:2375 without TLS is turned on.

Then install docker in WSL

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) stable"
sudo apt-get update
sudo apt-get install docker-ce

And set the env variable so that all docker commands go to the daemon exposed in windows

export DOCKER_HOST=tcp://localhost:2375

You can now enjoy your docker commands in WSL :-)

There are several tweaks and steps you still need to do to get wsl2 working with docker,

Have a look at https://codingfullstack.com/cloud/docker-installation-wsl2/ if you would like to know more about on how to get this working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM