qcloud安装docker

 qcloud: 

[ubuntu@VM-0-9-ubuntu:~]$ uname -a

Linux VM-0-9-ubuntu 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux



docker安装步骤参考官网
1、卸载旧版: 
sudo apt-get remove docker docker-engine docker.io containerd runc

2、   更新apt包: 
$ sudo apt-get update

$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

3、下载docker官方gpg key: 
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

4、增加source.list内容: 
 echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5、安装docker引擎:
 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

如果需要安装制定版本的docker,则需要查看repository中的可用版本: 
$ apt-cache madison docker-ce
 docker-ce | 5:20.10.12~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.11~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.10~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.9~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

第二列即为版本,如:5:20.10.12~3-0~ubuntu-focal,安装时使用如下: 
 sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

使用hello-world来确认docker引擎正确安装: 
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:97a379f4f88575512824f3b352bc03cd75e239179eea0fecc38e597b2209f49a
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

此命令下载一个hello-world的测试镜像 

docker用户组创建了,但没有用户加到改组,所以现在将ubuntu这个用户增加到docker组内: 
usermod -aG docker ubuntu


从安装包安装docker参考这里


docker使用: 
1、查找镜像和下载镜像: 
docker search ubuntu:20.04        #该命令相当于docker pull registry.hub.docker.com/ubuntu:20.04 命令,即从注册服务器registry.hub.docker.com中的ubuntu仓库下载标记为20.04的镜像
NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
manishfoodtechs/xfcefulldesktop_ubuntu20.4   Full Desktop In Docker : Ubuntu:20.04           5
delta42/ubuntu-with-openjdk-13               Ubuntu:20.04 with OpenJDK13 JRE installed       1
hanlinyang/openjdk                           AdoptOpenJDK based on hanlinyang/ubuntu:20.0…   0
bubuntux/s6-ubuntu                           Multi-platform Ubuntu:20.04 image with s6-ov…   0
wagner85/jks-slave                           ubuntu:20.04 - Jenkins slave                    0
mooping/apache2-php7                         Base on ubuntu:20.04                            0
julianqz/ubuntu                              Minimal Ubuntu:20.04                            0
sylketri/ubuntu20.04-latex                   LaTex Docker image based on ubuntu:20.04        0
hexiaoyuan/pete-dev-base                     ubuntu:20.04: include sshd, vim, gcc, python…   0
subha987/sshcontainer                        this uses ubuntu:20.04 as base image. this c…   0
taiansu/ubuntu-phoenix-builder               An Ubuntu:20.04 with necessary packages for …   0
best7777/ubus                                ubuntu:20.04  ssh and rdp and firefox instal…   0
artemkrim/universal-base-image               ubuntu:20.04 with cli-tools                     0
eiorobot/openjdk                             ubuntu:20.04&openjdk11                          0
julianqz/cellranger-6.0.1                    Cell Ranger v6.0.1 from 10x Genomics. Built …   0
eirture/mongosh                              the mongosh image base on ubuntu:20.04          0
clearcodecn/docker-headless-shell            ubuntu:20.04 based, see https://github.com/c…   0
alikazemkhanloo/miktex                       miktex on ubuntu:20.04, focal                   0
alby117/ubuntu_full                          Ubuntu:20.04 with software-properties-common…   0
lvhui/ubuntu-cpp-env                         ubuntu:20.04环境下的cpp开发调试环境 默认用户…                 0
aghaahmadi/mypython                          ubuntu:20.04 Python 3.8.10 wkhtmltopdf panda…   0
ixybus/ubvimgit                              Ubuntu:20.04 with Vim and Git installed         0
srivatsasrinath/ubuntu-base                  A simple ubuntu:20.04 base                      0
delimce/develemento                          ubuntu:20.04.1 / nginx / php-fpm 7.4 / nodejs   0
mastack/tbuilder                             this repository is made as a ready-to-use ub…   0

下载镜像: 
docker pull ubuntu:20.04 
#该命令相当于docker pull registry.hub.docker.com/ubuntu:20.04 命令,即从注册服务器registry.hub.docker.com中的ubuntu仓库下载标记为20.04的镜像

也可以指定仓库下载
docker pull dl.dockerpool.com:5000/ubuntu:20.04 

2、查看本地镜像: 
docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
ubuntu        20.04     54c9d81cbb44   12 days ago    72.8MB
hello-world   latest    feb5d9fea6a5   4 months ago   13.3kB

3、启动容器并进入bash(执行命令后,当前窗口就是在容器内了)
#ubuntu:20.04=> name:tag   ,   (-t 让Docker分配一个伪终端(pseudo-tty)并绑定到容器的标准输入上,-i 则让容器的标准输入保持打开
docker run -it ubuntu:20.04 /bin/bash 
4、查看运行中的容器(另外新开一个terminal执行这个命令)
docker ps -l查看最近的一个容器;docker ps -a查看所有容器
[ubuntu@VM-0-9-ubuntu:~]$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED              STATUS                      PORTS     NAMES
a081cbe1a519   ubuntu:20.04   "/bin/bash"   About a minute ago   Up About a minute                     blissful_pare
78ec522a0b48   hello-world    "/hello"      51 minutes ago       Exited (0) 51 minutes ago             sweet_saha
[ubuntu@VM-0-9-ubuntu:~]$ docker ps -l
CONTAINER ID   IMAGE          COMMAND       CREATED              STATUS              PORTS     NAMES
a081cbe1a519   ubuntu:20.04   "/bin/bash"   About a minute ago   Up About a minute             blissful_pare

5、查看容器的详细信息: 
docker inspect <container id>:容器ID一般取前几位即可。
[ubuntu@VM-0-9-ubuntu:~]$ docker inspect a081cbe1a519
[
    {
        "Id": "a081cbe1a51923fc09ccfa3b95208e15be549d7233e08fff7824c942e189fe99",
        "Created": "2022-02-14T07:56:36.286899177Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 1476,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-02-14T07:56:36.801022372Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:54c9d81cbb440897908abdcaa98674db83444636c300170cfd211e40a66f704f",
        "ResolvConfPath": "/var/lib/docker/containers/a081cbe1a51923fc09ccfa3b95208e15be549d7233e08fff7824c942e189fe99/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/a081cbe1a51923fc09ccfa3b95208e15be549d7233e08fff7824c942e189fe99/hostname",
        "HostsPath": "/var/lib/docker/containers/a081cbe1a51923fc09ccfa3b95208e15be549d7233e08fff7824c942e189fe99/hosts",
        "LogPath": "/var/lib/docker/containers/a081cbe1a51923fc09ccfa3b95208e15be549d7233e08fff7824c942e189fe99/a081cbe1a51923fc09ccfa3b95208e15be549d7233e08fff7824c942e189fe99-json.log",
        "Name": "/blissful_pare",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/069fbfdfdd7c40fb6e63786d2ac9975f9539ed859c49e89e2b5da853f2cb7f32-init/diff:/var/lib/docker/overlay2/6de09465fda78cc67d42cf3b4c284e6b6b1dffbb8ce4809f08f0fd4d36d85143/diff",
                "MergedDir": "/var/lib/docker/overlay2/069fbfdfdd7c40fb6e63786d2ac9975f9539ed859c49e89e2b5da853f2cb7f32/merged",
                "UpperDir": "/var/lib/docker/overlay2/069fbfdfdd7c40fb6e63786d2ac9975f9539ed859c49e89e2b5da853f2cb7f32/diff",
                "WorkDir": "/var/lib/docker/overlay2/069fbfdfdd7c40fb6e63786d2ac9975f9539ed859c49e89e2b5da853f2cb7f32/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "a081cbe1a519",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "ubuntu:20.04",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "85f3cef8437f2edec72a4efe320f6ecf67dedec84f5cff66dbd2a3951104afd0",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/85f3cef8437f",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "7599c24030c7fcd2921bc87ec7f248d19ef1931011ddd1e53182c4f2e3bb3418",
            "Gateway": "172.18.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.18.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:12:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "edb155816c7bd865d98511e1ace08e77e3ff5b5f32676748766f88418193b4c8",
                    "EndpointID": "7599c24030c7fcd2921bc87ec7f248d19ef1931011ddd1e53182c4f2e3bb3418",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]
6、移除容器:docker rm <container id>
删除所有容器: docker rm ${docker ps -a -q}
[ubuntu@VM-0-9-ubuntu:~]$ docker rm 78ec522a0b48
78ec522a0b48
7、移除镜像:docker rmi <image id>,移除镜像前需要移除依赖于这个镜像的所有容器。
移除所有镜像:docker rmi ${docker ps -a -q}
[ubuntu@VM-0-9-ubuntu:~]$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
ubuntu        20.04     54c9d81cbb44   12 days ago    72.8MB
hello-world   latest    feb5d9fea6a5   4 months ago   13.3kB
[ubuntu@VM-0-9-ubuntu:~]$ docker rmi feb5d9fea6a5
Untagged: hello-world:latest
Untagged: hello-world@sha256:97a379f4f88575512824f3b352bc03cd75e239179eea0fecc38e597b2209f49a
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
[ubuntu@VM-0-9-ubuntu:~]$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       20.04     54c9d81cbb44   12 days ago   72.8MB

8、docker的启动和停止
docker start/stop <container id>
[ubuntu@VM-0-9-ubuntu:~]$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS         PORTS     NAMES
a081cbe1a519   ubuntu:20.04   "/bin/bash"   9 minutes ago   Up 9 minutes             blissful_pare
[ubuntu@VM-0-9-ubuntu:~]$ docker stop a081cbe1a519
a081cbe1a519
[ubuntu@VM-0-9-ubuntu:~]$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS                      PORTS     NAMES
a081cbe1a519   ubuntu:20.04   "/bin/bash"   9 minutes ago   Exited (0) 36 seconds ago             blissful_pare
[ubuntu@VM-0-9-ubuntu:~]$ docker start a081cbe1a519
a081cbe1a519
[ubuntu@VM-0-9-ubuntu:~]$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS         PORTS     NAMES
a081cbe1a519   ubuntu:20.04   "/bin/bash"   11 minutes ago   Up 4 seconds             blissful_pare  

9、容器重命名:
docker rename ubuntu:20.04 newname

10、使用attach进入已启动的容器(注意:attach到容器上的所有窗口的输入输出会同步)
[ubuntu@VM-0-9-ubuntu:~]$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88dbf223ba80 ubuntu:20.04 "/bin/bash" 18 seconds ago Up 16 seconds busy_cartwright a081cbe1a519 ubuntu:20.04 "/bin/bash" 14 minutes ago Up 2 minutes blissful_pare [ubuntu@VM-0-9-ubuntu:~]$ docker attach 88dbf223ba80 root@88dbf223ba80:/# 

[ubuntu@VM-0-9-ubuntu:~]$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88dbf223ba80 ubuntu:20.04 "/bin/bash" About a minute ago Exited (1) 6 seconds ago busy_cartwright a081cbe1a519 ubuntu:20.04 "/bin/bash" 15 minutes ago Up 4 minutes blissful_pare [ubuntu@VM-0-9-ubuntu:~]$ docker stop 88dbf223ba80 88dbf223ba80 [ubuntu@VM-0-9-ubuntu:~]$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88dbf223ba80 ubuntu:20.04 "/bin/bash" 2 minutes ago Exited (1) 14 seconds ago busy_cartwright a081cbe1a519 ubuntu:20.04 "/bin/bash" 15 minutes ago Up 4 minutes blissful_pare [ubuntu@VM-0-9-ubuntu:~]$ docker start 88dbf223ba80 88dbf223ba80 [ubuntu@VM-0-9-ubuntu:~]$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88dbf223ba80 ubuntu:20.04 "/bin/bash" 2 minutes ago Up 2 seconds busy_cartwright a081cbe1a519 ubuntu:20.04 "/bin/bash" 16 minutes ago Up 5 minutes blissful_pare

11、访问某一个容器:
可以执行: docker run -it image_id,启动一个容器 
docker run -it ubuntu:20.04 /bin/bash

或者先docker start <container id> ,然后在docker attach <container id>
[ubuntu@VM-0-9-ubuntu:~]$ docker start a081cbe1a519 a081cbe1a519 [ubuntu@VM-0-9-ubuntu:~]$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88dbf223ba80 ubuntu:20.04 "/bin/bash" 8 minutes ago Exited (0) 38 seconds ago busy_cartwright a081cbe1a519 ubuntu:20.04 "/bin/bash" 21 minutes ago Up 1 second blissful_pare [ubuntu@VM-0-9-ubuntu:~]$ docker attach a081cbe1a519 root@a081cbe1a519:/#


11、持久化容器和镜像(容器和镜像制作)
通过容器生成新的镜像,运行中的镜像成为容器,你可以修改容器(增加或删除一个软件),但这些修改不会影响到镜像,不过可以使用docker commit把正在运行的容器变成一个新的镜像。
docker commit <container id> [repo:tag] #将一个container固化为一个新的image,后面的repo:tag可选
root@a081cbe1a519:/# apt install vim git

[ubuntu@VM-0-9-ubuntu:~]$ docker commit a081cbe1a519 scott_ubuntu20:dev sha256:a359d61c57d89b8a9be14b8fd6e994898c1cb3c8703d37415b51f296d64fdb5c [ubuntu@VM-0-9-ubuntu:~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE scott_ubuntu20 dev a359d61c57d8 19 seconds ago 270MB ubuntu 20.04 54c9d81cbb44 12 days ago 72.8MB


导出容器:export 命令用于持久化容器。
docker export <container id> /tmp/save_container.tar
[ubuntu@VM-0-9-ubuntu:~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE scott_ubuntu20 dev a359d61c57d8 17 minutes ago 270MB ubuntu 20.04 54c9d81cbb44 12 days ago 72.8MB [ubuntu@VM-0-9-ubuntu:~]$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3253acf90434 a359d61c57d8 "/bin/bash" 10 minutes ago Up 10 minutes reverent_tharp 88dbf223ba80 ubuntu:20.04 "/bin/bash" 40 minutes ago Exited (0) 33 minutes ago busy_cartwright a081cbe1a519 ubuntu:20.04 "/bin/bash" 54 minutes ago Exited (0) 18 minutes ago blissful_pare

[ubuntu@VM-0-9-ubuntu:~]$ docker export 3253acf90434 >  /tmp/save_container.tar

保存镜像: docker save <image id> /tmp/save_img.tar
[ubuntu@VM-0-9-ubuntu:~]$ docker save a359d61c57d8 > /tmp/save_img.tar

[ubuntu@VM-0-9-ubuntu:~]$ ls /tmp/ | grep tar
-rw-rw-r--  1 ubuntu ubuntu 265M Feb 14 16:54 save_img.tar
-rw-rw-r--  1 ubuntu ubuntu 264M Feb 14 16:53 save_container.tar

以下源自这里

4、导入容器  (import命令用于导入容器)

docker rm <CONTAINER ID>     #例子:先删除container 2161509ff65e

cat /tmp/export.tar | docker import - export:latest      #导入export.tar文件

5、导入镜像   (load 命令用于导入镜像)


docker rmi <IMAGE ID>      #删除image daa11948e23d,$ docker rmi daa11948e23d

docker load < /tmp/save.tar     #导入save.tar文件

docker tag <IMAGE ID>  load:tag    #对image打tag

6、 export-import与save-load的区别


导出后再导入(export-import)的镜像会丢失所有的历史,而保存后再加载(save-load)的镜像没有丢失历史和层(layer)。这意味着使用导出后再导入的方式,你将无法回滚到之前的层(layer),同时,使用保存后再加载的方式持久化整个镜像,就可以做到层回滚。(可以执行docker tag 来回滚之前的层)。


docker 问题: 
1)、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/images/json": dial unix /var/run/docker.sock: connect: permission denied
sudo groupadd docker #创建docker组,如果已存在则无须创建
sudo usermod -aG docker $USER #将当前用户(或指定用户)加到docker组
 
#确认下当前用户(或指定用户)已加入docker组,当然你可能需要登出一下
groups

#如果登出以后,发现依然没有加入到docker组内,则可能需要重启服务器
#为了避免重启服务器,可以执行以下命令
newgrp docker
#然后后续执行docker命令时,就不会再报错了。