官网安装步骤
-
卸载旧版本
sudo apt-get remove docker docker-engine docker.io containerd runc
-
设置仓库
sudo apt-get updatesudo apt-get install \apt-transport-https \ca-certificates \curl \gnupg \lsb-release
-
添加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
4.<a name="a7b621eb"></a>## 安装Docker```markdownsudo apt-get updatesudo apt-get install docker-ce docker-ce-cli containerd.io
-
安装指定版本
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
-
验证安装
sudo docker run hello-world
-
预期结果
```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:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the “hello-world” image from the Docker Hub. (amd64)
- The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
- 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/
<a name="0dfbe902"></a># 常用命令```markdown### 启动sudo systemctl start docker### 关闭sudo systemctl stop docker### 重启sudo systemctl restart docker### 自启动sudo systemctl enable docker### 查看状态sudo systemctl status docker### 查看容器内运行状态sudo docker stats### 查看概要信息sudo docker info### 查看帮助文档sudo docker --help
安装校验
docker -vDocker version 20.10.7, build f0df350docker versionClient: Docker Engine - CommunityVersion: 20.10.7API version: 1.41Go version: go1.13.15Git commit: f0df350Built: Wed Jun 2 11:56:40 2021OS/Arch: linux/amd64Context: defaultExperimental: trueServer: Docker Engine - CommunityEngine:Version: 20.10.7API version: 1.41 (minimum version 1.12)Go version: go1.13.15Git commit: b0f5bc3Built: Wed Jun 2 11:54:48 2021OS/Arch: linux/amd64Experimental: falsecontainerd:Version: 1.4.8GitCommit: 7eba5930496d9bbe375fdf71603e610ad737d2b2runc:Version: 1.0.0GitCommit: v1.0.0-0-g84113eedocker-init:Version: 0.19.0GitCommit: de40ad0
其他命令
### 查看镜像docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest d1165f221234 4 months ago 13.3kB
配置源
[root@vvkt7whznuckhiz2-0723575 ~]# sudo vim /etc/docker/daemon.json{"registry-mirrors":["http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]}
重新加载
sudo systemctl daemon-reloadsudo systemctl restart docker
拉取测试
### 拉取逻辑1. 本地查找2. 远程仓库拉取root@vvkt7whznuckhiz2-0723575:~# docker pull nginxUsing default tag: latestlatest: Pulling from library/nginx33847f680f63: Pull completedbb907d5159d: Pull complete8a268f30c42a: Pull completeb10cf527a02d: Pull completec90b090c213b: Pull complete1f41b2f2bf94: Pull completeDigest: sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90Status: Downloaded newer image for nginx:latestdocker.io/library/nginx:latest
Windows10 安装Docker
1. 需要启用Hyper-V2. 需要安装WSL3. 需要安装低版本WSL# 补充:下载链接https://czf-net.xyz/res/# 端口映射docker run -d -p 20000:80 docker/getting-started
CentOS安装Docker
下载地址:
链接
安装命令
[root@localhost tylor]# history1 sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine2 sudo yum install -y yum-utils3 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo4 sudo yum-config-manager --enable docker-ce-nightly5 sudo yum install docker-ce docker-ce-cli containerd.io6 sudo systemctl start docker7 sudo docker run hello-world
换源
