官网安装步骤

  1. 卸载旧版本

    1. sudo apt-get remove docker docker-engine docker.io containerd runc
  2. 设置仓库

    1. sudo apt-get update
    2. sudo apt-get install \
    3. apt-transport-https \
    4. ca-certificates \
    5. curl \
    6. gnupg \
    7. lsb-release
  3. 添加GPG key

    ```bash curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg —dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \ “deb [arch=amd64 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

  1. 4.
  2. <a name="a7b621eb"></a>
  3. ## 安装Docker
  4. ```markdown
  5. sudo apt-get update
  6. sudo apt-get install docker-ce docker-ce-cli containerd.io
  1. 安装指定版本

    1. sudo apt-get install docker-ce=5:20.10.7~3-0~ubuntu-bionic docker-ce-cli=5:20.10.7~3-0~ubuntu-bionic containerd.io
  2. 验证安装

    1. sudo docker run hello-world
  3. 预期结果

    ```bash Unable to find image ‘hello-world:latest’ locally latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e 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/

  1. <a name="0dfbe902"></a>
  2. # 常用命令
  3. ```markdown
  4. ### 启动
  5. sudo systemctl start docker
  6. ### 关闭
  7. sudo systemctl stop docker
  8. ### 重启
  9. sudo systemctl restart docker
  10. ### 自启动
  11. sudo systemctl enable docker
  12. ### 查看状态
  13. sudo systemctl status docker
  14. ### 查看容器内运行状态
  15. sudo docker stats
  16. ### 查看概要信息
  17. sudo docker info
  18. ### 查看帮助文档
  19. sudo docker --help

安装校验

  1. docker -v
  2. Docker version 20.10.7, build f0df350
  3. docker version
  4. Client: Docker Engine - Community
  5. Version: 20.10.7
  6. API version: 1.41
  7. Go version: go1.13.15
  8. Git commit: f0df350
  9. Built: Wed Jun 2 11:56:40 2021
  10. OS/Arch: linux/amd64
  11. Context: default
  12. Experimental: true
  13. Server: Docker Engine - Community
  14. Engine:
  15. Version: 20.10.7
  16. API version: 1.41 (minimum version 1.12)
  17. Go version: go1.13.15
  18. Git commit: b0f5bc3
  19. Built: Wed Jun 2 11:54:48 2021
  20. OS/Arch: linux/amd64
  21. Experimental: false
  22. containerd:
  23. Version: 1.4.8
  24. GitCommit: 7eba5930496d9bbe375fdf71603e610ad737d2b2
  25. runc:
  26. Version: 1.0.0
  27. GitCommit: v1.0.0-0-g84113ee
  28. docker-init:
  29. Version: 0.19.0
  30. GitCommit: de40ad0

其他命令

  1. ### 查看镜像
  2. docker images
  3. REPOSITORY TAG IMAGE ID CREATED SIZE
  4. hello-world latest d1165f221234 4 months ago 13.3kB

配置源

  1. [root@vvkt7whznuckhiz2-0723575 ~]# sudo vim /etc/docker/daemon.json
  2. {
  3. "registry-mirrors":["http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]
  4. }

重新加载

  1. sudo systemctl daemon-reload
  2. sudo systemctl restart docker

拉取测试

  1. ### 拉取逻辑
  2. 1. 本地查找
  3. 2. 远程仓库拉取
  4. root@vvkt7whznuckhiz2-0723575:~# docker pull nginx
  5. Using default tag: latest
  6. latest: Pulling from library/nginx
  7. 33847f680f63: Pull complete
  8. dbb907d5159d: Pull complete
  9. 8a268f30c42a: Pull complete
  10. b10cf527a02d: Pull complete
  11. c90b090c213b: Pull complete
  12. 1f41b2f2bf94: Pull complete
  13. Digest: sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90
  14. Status: Downloaded newer image for nginx:latest
  15. docker.io/library/nginx:latest

Windows10 安装Docker

  1. 1. 需要启用Hyper-V
  2. 2. 需要安装WSL
  3. 3. 需要安装低版本WSL
  4. # 补充:下载链接
  5. https://czf-net.xyz/res/
  6. # 端口映射
  7. docker run -d -p 20000:80 docker/getting-started

CentOS安装Docker

下载地址:
链接

安装命令

  1. [root@localhost tylor]# history
  2. 1 sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
  3. 2 sudo yum install -y yum-utils
  4. 3 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  5. 4 sudo yum-config-manager --enable docker-ce-nightly
  6. 5 sudo yum install docker-ce docker-ce-cli containerd.io
  7. 6 sudo systemctl start docker
  8. 7 sudo docker run hello-world

换源