WSL2 安装 Docker
方式一:Docker Desktop+WSL2 运行 Docker
 Docker Desktop 将 Docker CE、Docker Compose、Kubernets 等软件整合在了一起进行安装,省去了一一安装的烦恼。Docker Daemon 由于是安装在宿主机上的,因此可以直接使用宿主机的网卡信息对容器进行访问。
下载安装Docker Desktop运行 Docker,可以让你在Windows中方便的管理配置Docker
 Docker for Windows:https://desktop.docker.com/win/stable/Docker%20Desktop%20Installer.exe
 Doecker for Mac:https://desktop.docker.com/mac/stable/Docker.dmg
 傻瓜式安装即可!配置Docker Desktop使用WSL2运行Docker engine
 现在你就可以在对应的子系统中玩 Docker 了,打开安装好的子系统,输入docker info就可以查看到对应的系统信息了.踩坑预警
 使用docker info打印信息时可能会遇到下述信息,提示/var/run/docker.sock权限不足Client:
 Debug Mode: falseServer:
 ERROR: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/info: dial unix /var/run/docker.sock: connect: permission denied
 errors pretty printing info
 图片/var/run/docker.sock connect permission denied
 通过ls -al /var/run/docker.sock查看该文件权限信息,发现文件是root用户或docker组用户才能进行读写图片
ls -al show files info
 可以通过id或groups ${USER}查看当前用户所在的组信息,发现当前用户的附加组信息里并没有docker,那么问题就好解决了:只需将当前用户加入到docker组即可.图片
id show ${USER} groups
 创建 docker 组
 sudo groupadd docker
 将当前用户加入到docker组
 sudo usermod -aG docker ${USER}
 刷新用户的用户组信息
 你需要先登出再重新登录一次,这样当前系统会重新刷新你的身份信息。或者,使用下列方式不用退出即可刷新当前进程的用户身份信息:exec su -l ${USER}
 此时再运行docker info应该就正常打印信息了!安装最新Docker Compose
 可参考:https://docs.docker.com/compose/install/#install-compose-on-linux-systems下载当前最新版本是:1.27.4
sudo curl -L “https://github.com/docker/compose/releases/download/1.27.4/docker-compose-(uname -m)” -o /usr/local/bin/docker-compose赋予 docker-compose 可执行权限
sudo chmod +x /usr/local/bin/docker-compose
刷新当前进程信息
exec $SHELL -l
检查docker-compose是否安装成功
docker-compose --version
 设置Docker Server镜像源加速
 Docker 官方中国区镜像地址:https://registry.docker-cn.com
 网易镜像地址:http://hub-mirror.c.163.com
 ustc镜像地址:https://docker.mirrors.ustc.edu.cn
 阿里云镜像地址设置参考文章底部:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
 如果想使用阿里云镜像地址需要有阿里云账号,但我在广州试用了上述的镜像地址,确实设置了阿里云的镜像加速是效果最好的通过Docker Desktop配置registry-mirrors
 如果是使用 Docker Desktop+WSL 方式安装 Docker 直接使用面板即可修改!{
 “experimental”: false,
 “debug”: true,
 “registry-mirrors”: [
 “https://xxxxxx.mirror.aliyuncs.com”,
 “http://hub-mirror.c.163.com”
 ]
 }增加镜像只需要配置 registry-mirrors,对应一个集合,我配置了网易的镜像和阿里云的镜像
{
 “experimental”: false,
 “debug”: true,
 “registry-mirrors”: [
 “https://xxxxxx.mirror.aliyuncs.com”,
 “http://hub-mirror.c.163.com”
 ]
 }yyp@DESKTOP-U0COGSO:~$ docker
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
 –config string Location of client config files (default “/home/yyp/.docker”)
 -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and
 default context set with “docker context use”)
 -D, --debug Enable debug mode
 -H, --host list Daemon socket(s) to connect to
 -l, --log-level string Set the logging level (“debug”|“info”|“warn”|“error”|“fatal”) (default “info”)
 –tls Use TLS; implied by --tlsverify
 –tlscacert string Trust certs signed only by this CA (default “/home/yyp/.docker/ca.pem”)
 –tlscert string Path to TLS certificate file (default “/home/yyp/.docker/cert.pem”)
 –tlskey string Path to TLS key file (default “/home/yyp/.docker/key.pem”)
 –tlsverify Use TLS and verify the remote
 -v, --version Print version information and quitManagement Commands:
 app* Docker App (Docker Inc., v0.9.1-beta3)
 builder Manage builds
 buildx* Build with BuildKit (Docker Inc., v0.5.1-docker)
 config Manage Docker configs
 container Manage containers
 context Manage contexts
 image Manage images
 manifest Manage Docker image manifests and manifest lists
 network Manage networks
 node Manage Swarm nodes
 plugin Manage plugins
 scan* Docker Scan (Docker Inc., v0.5.0)
 secret Manage Docker secrets
 service Manage services
 stack Manage Docker stacks
 swarm Manage Swarm
 system Manage Docker
 trust Manage trust on Docker images
 volume Manage volumesCommands:
 attach Attach local standard input, output, and error streams to a running container
 build Build an image from a Dockerfile
 commit Create a new image from a container’s changes
 cp Copy files/folders between a container and the local filesystem
 create Create a new container
 diff Inspect changes to files or directories on a container’s filesystem
 events Get real time events from the server
 exec Run a command in a running container
 export Export a container’s filesystem as a tar archive
 history Show the history of an image
 images List images
 import Import the contents from a tarball to create a filesystem image
 info Display system-wide information
 inspect Return low-level information on Docker objects
 kill Kill one or more running containers
 load Load an image from a tar archive or STDIN
 login Log in to a Docker registry
 logout Log out from a Docker registry
 logs Fetch the logs of a container
 pause Pause all processes within one or more containers
 port List port mappings or a specific mapping for the container
 ps List containers
 pull Pull an image or a repository from a registry
 push Push an image or a repository to a registry
 rename Rename a container
 restart Restart one or more containers
 rm Remove one or more containers
 rmi Remove one or more images
 run Run a command in a new container
 save Save one or more images to a tar archive (streamed to STDOUT by default)
 search Search the Docker Hub for images
 start Start one or more stopped containers
 stats Display a live stream of container(s) resource usage statistics
 stop Stop one or more running containers
 tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
 top Display the running processes of a container
 unpause Unpause all processes within one or more containers
 update Update configuration of one or more containers
 version Show the Docker version information
 wait Block until one or more containers stop, then print their exit codesRun ‘docker COMMAND --help’ for more information on a command.
To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
 yyp@DESKTOP-U0COGSO:~$ docker info
 Client:
 Context: default
 Debug Mode: false
 Plugins:
 app: Docker App (Docker Inc., v0.9.1-beta3)
 buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
 scan: Docker Scan (Docker Inc., v0.5.0)Server:
 ERROR: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info: dial unix /var/run/docker.sock: connect: permission denied
 errors pretty printing info
 yyp@DESKTOP-U0COGSO:~$ ls -al /var/run/docker.sock
 srw-rw---- 1 root docker 0 Jan 17 15:27 /var/run/docker.sock
 yyp@DESKTOP-U0COGSO:~$ id
 uid=1000(yyp) gid=1000(yyp) groups=1000(yyp),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),117(netdev)
 yyp@DESKTOP-U0COGSO:~$
 yyp@DESKTOP-U0COGSO:~$
 yyp@DESKTOP-U0COGSO:~$
 yyp@DESKTOP-U0COGSO:~$ sudo groupadd docker
 groupadd: group ‘docker’ already exists
 yyp@DESKTOP-U0COGSO:~$ sudo usermod -aG docker  exec su -l  docker info
 Client:
 Context: default
 Debug Mode: false
 Plugins:
 app: Docker App (Docker Inc., v0.9.1-beta3)
 buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
 scan: Docker Scan (Docker Inc., v0.5.0)Server:
 Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
 Images: 0
 Server Version: 20.10.2
 Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 init version: de40ad0
 Security Options:
 seccomp
 Profile: default
 Kernel Version: 4.19.128-microsoft-standard
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 25.02GiB
 Name: docker-desktop
 ID: F43Y:4N6C:5FE3:X7TX:PB5S:WBBZ:7I4B:PVXG:VDZH:GBWT:LCJK:DJZH
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
 File Descriptors: 40
 Goroutines: 45
 System Time: 2021-01-17T07:31:55.8171453Z
 EventsListeners: 4
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
 127.0.0.0/8
 Live Restore Enabled: falseWARNING: No blkio weight support
 WARNING: No blkio weight_device support
 WARNING: No blkio throttle.read_bps_device support
 WARNING: No blkio throttle.write_bps_device support
 WARNING: No blkio throttle.read_iops_device support
 WARNING: No blkio throttle.write_iops_device support
 WARNING: bridge-nf-call-iptables is disabled
 WARNING: bridge-nf-call-ip6tables is disabledyyp@DESKTOP-U0COGSO:~$ sudo curl -L “https://github.com/docker/compose/releases/download/1.27.4/docker-compose-(uname -m)” -o /usr/local/bin/docker-compose
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
 100 651 100 651 0 0 315 0 0:00:02 0:00:02 --:–:-- 315
 100 11.6M 100 11.6M 0 0 21881 0 0:09:18 0:09:18 --:–:-- 25694
 yyp@DESKTOP-U0COGSO:~$ sudo chmod +x /usr/local/bin/docker-compose
 yyp@DESKTOP-U0COGSO:~$ exec  docker-compose --version
 docker-compose version 1.27.4, build 40524192
 yyp@DESKTOP-U0COGSO:~$ docker ps
 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
 yyp@DESKTOP-U0COGSO:~$