Tutorial on installing Docker in Windows 10 subsystem Ubuntu (WSL) (with pictures and text)

Tutorial on installing Docker in Windows 10 subsystem Ubuntu (WSL) (with pictures and text)

Environmental Description

Environment: Win10 Enterprise Edition + Ubuntu 18.04 LTS [WSL]

Install Docker for Windows on Windows 10

Now Docker has a special installation package for Win10 Professional system, which requires Hyper-V to be enabled.

Enable Hyper-V

insert image description here

Programs and Features


insert image description here

Turn Windows features on or off


insert image description here

Select Hyper-V


insert image description here

Install Docker for Windows

Latest version of Docker for Windows

Download address: https://docs.docker.com/v17.09/docker-for-windows/install/

Click Get Docker for Windows [Stable] and download the Windows version:

insert image description here

After the installation is complete, Docker will start automatically. A small whale icon will appear on the notification barinsert image description here , which means Docker is running.

Three icons will also appear on the table, as shown below:

We can execute docker version in the command line to view the version number and docker run hello-world to load the test image for testing.

If it is not started, you can search for Docker in Windows to start it:


insert image description here

After starting, you can also see the little whale icon in the notification bar:


insert image description here

Subsystem installation Docker installation

No problem

leenhem@DESKTOP-7SREO20:~$ sudo apt-get install docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
docker.io is already the newest version (18.09.7-0ubuntu1~18.04.4).
0 upgraded, 0 newly installed, 0 to remove and 111 not upgraded.

There is a problem with the use [cannot be used normally]

Official website explanation

leenhem@DESKTOP-7SREO20:~$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status
 * Docker is not running
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker start
 * Starting Docker: docker [ OK ] 
leenhem@DESKTOP-7SREO20:~$ 
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status
 * Docker is running
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status
 * Docker is not running

You will find that Docker cannot be started at all. What should I do now? Be sure to check the log first (/var/log/docker.log)
leenhem@DESKTOP-7SREO20:~$ tail /var/log/docker.log -n 100

time="2019-10-22T11:58:25.436968100+08:00" level=info msg="ccResolverWrapper: sending new addresses to cc: [{unix:///var/run/docker/containerd/containerd.sock 0 <nil>}]" module=grpc
time="2019-10-22T11:58:25.437359900+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
time="2019-10-22T11:58:25.437703900+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, CONNECTING" module=grpc
time="2019-10-22T11:58:25.438698400+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, READY" module=grpc
time="2019-10-22T11:58:25.559058900+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
time="2019-10-22T11:58:25.719182400+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
time="2019-10-22T11:58:25.719593400+08:00" level=warning msg="Your kernel does not support cgroup memory limit"
time="2019-10-22T11:58:25.719660300+08:00" level=warning msg="Unable to find cpu cgroup in mounts"
time="2019-10-22T11:58:25.719697200+08:00" level=warning msg="Unable to find blkio cgroup in mounts"
time="2019-10-22T11:58:25.719732900+08:00" level=warning msg="Unable to find cpuset cgroup in mounts"
time="2019-10-22T11:58:25.719888000+08:00" level=warning msg="mountpoint for pids not found"
time="2019-10-22T11:58:25.721991900+08:00" level=info msg="stopping healthcheck following graceful shutdown" module=libcontainerd
time="2019-10-22T11:58:25.722045300+08:00" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
time="2019-10-22T11:58:25.723869300+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, TRANSIENT_FAILURE" module=grpc
time="2019-10-22T11:58:25.724042800+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, CONNECTING" module=grpc
Error starting daemon: Devices cgroup isn't mounted

Preliminary conclusion: The WIN10 kernel cannot fully simulate the cgroup and aufs components of Linux

Official website explanation [Solution]

[Cross Post] WSL Interoperability with Docker

https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

apt install screenfetch
screenfetch

Script: https://files.cnblogs.com/files/rgqancy/WSL.js, download and save as txt

Establishing a relay

Now that Go is installed, we can build relay. In the commands below, be sure to replace with your Windows username:

go get -d github.com/jstarks/npiperelay
GOOS=windows go build -o /mnt/c/Users/Administrator/go/bin/npiperelay.exe github.com/jstarks/npiperelay

We have the relay built for Windows now, but we want it to be callable from within WSL. To do this, we create a symbolic link. Make sure to replace: with your Windows username:

sudo ln -s /mnt/c/Users/Administrator/go/bin/npiperelay.exe /usr/local/bin/npiperelay.exe

We will use socat to help enable relaying. Install socat, a tool that allows data to flow in both directions between two points (more on this later). Grab this package:

sudo apt install socat

Final Step

With socat installed and the executable built, we just need to string a few things together. We will make a shell script to activate our functionality. We will place this in our user's home directory. To do this:

#make the file
touch ~/docker-relay
#add execution privileges
chmod +x ~/docker-relay

Open the file we created with your favorite text editor (like vim). Paste this into the file docker-relay:

#!/bin/sh
exec socat UNIX-LISTEN:/var/run/docker.sock,fork,group=docker,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/docker_engine",nofork

Save the file and close it. The docker-relay script configures the Docker pipeline to allow access by the docker group. To run as a normal user (without having to append 'sudo' to every docker command), add your WSL user to the docker group. In Ubuntu:

sudo adduser <your WSL user> docker

Let’s test it!

Open a new WSL shell to ensure your group membership is reset. Start the relay in the background:

sudo ~/docker-relay &

Now run the docker command to test the waters. You should be greeted by the same output as if you had run the command from Windows (and note that you don't need to prefix the command with 'sudo'!)

Notice

To start Docker for Windows in advance


insert image description here

Schematic

There is a fundamental problem with getting the Docker client running under WSL to communicate with Docker for Windows: the WSL client understands IPC over unix sockets, while Docker for Windows understands IPC over named pipes. This is where socat and npiperelay.exe come into play – it is the mediator between these two disjoint forms of IPC. Socat understands how to communicate over unix sockets, npiperelay understands how to communicate over named pipes. Both socat and npiperelay understand how to communicate over stdio, so they can communicate with each other.


insert image description here

Summarize

The above is the tutorial on how to install Docker in win10 subsystem ubuntu (WSL) introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to make a tar file of wsl through Docker
  • Detailed process of deploying Docker to WSL2 in IDEA
  • Installing Docker Desktop reports an error message: WSL 2 installation is incomplete (Solve the error message)
  • How to install WSL2 Ubuntu20.04 on Windows 10 and set up the docker environment
  • About WSL configuration and modification issues in Docker

<<:  Mini Program to Implement Text Circular Scrolling Animation

>>:  WeChat applet realizes chat room function

Recommend

A brief discussion on this.$store.state.xx.xx in Vue

Table of contents Vue this.$store.state.xx.xx Get...

33 of the best free English fonts shared

ChunkFive Free Typefamily Cuprum JAH I Free font Y...

How to implement image mapping with CSS

1. Introduction Image maps allow you to designate...

Multiple ways to insert SVG into HTML pages

SVG (Scalable Vector Graphics) is an image format...

Record a slow query event caused by a misjudgment of the online MySQL optimizer

Preface: I received crazy slow query and request ...

MySQL 5.7.17 installation and configuration graphic tutorial

The blogger said : I have been writing a series o...

Node.js sends emails based on STMP protocol and EWS protocol

Table of contents 1 Node.js method of sending ema...

Completely delete MySQL steps

Table of contents 1. Stop MySQL Server first 2. U...

Detailed explanation of JavaScript function this pointing problem

Table of contents 1. The direction of this in the...

Mini Program to Implement Sieve Lottery

This article example shares the specific code of ...

Detailed examples of Zabbix remote command execution

Table of contents one. environment two. Precautio...

How to make JavaScript sleep or wait

Table of contents Overview Checking setTimeout() ...