官网安装步骤
-
卸载旧版本
sudo apt-get remove docker docker-engine docker.io containerd runc
-
设置仓库
sudo apt-get update
sudo 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
```markdown
sudo apt-get update
sudo 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 -v
Docker version 20.10.7, build f0df350
docker version
Client: Docker Engine - Community
Version: 20.10.7
API version: 1.41
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:56:40 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:48 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.8
GitCommit: 7eba5930496d9bbe375fdf71603e610ad737d2b2
runc:
Version: 1.0.0
GitCommit: v1.0.0-0-g84113ee
docker-init:
Version: 0.19.0
GitCommit: de40ad0
其他命令
### 查看镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-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-reload
sudo systemctl restart docker
拉取测试
### 拉取逻辑
1. 本地查找
2. 远程仓库拉取
root@vvkt7whznuckhiz2-0723575:~# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
33847f680f63: Pull complete
dbb907d5159d: Pull complete
8a268f30c42a: Pull complete
b10cf527a02d: Pull complete
c90b090c213b: Pull complete
1f41b2f2bf94: Pull complete
Digest: sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
Windows10 安装Docker
1. 需要启用Hyper-V
2. 需要安装WSL
3. 需要安装低版本WSL
# 补充:下载链接
https://czf-net.xyz/res/
# 端口映射
docker run -d -p 20000:80 docker/getting-started
CentOS安装Docker
下载地址:
链接
安装命令
[root@localhost tylor]# history
1 sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
2 sudo yum install -y yum-utils
3 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4 sudo yum-config-manager --enable docker-ce-nightly
5 sudo yum install docker-ce docker-ce-cli containerd.io
6 sudo systemctl start docker
7 sudo docker run hello-world
换源