官方地址
apt-get remove docker docker-engine docker.io containerd runc && apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
rm -rf /etc/docker && rm -rf /usr/libexec/docker && rm -rf /var/lib/docker && rm -rf /var/lib/containerd && rm -rf /etc/apt/keyrings
whereis docker # 确保没有和docker相关的文件
apt-get update && apt-get install ca-certificates curl gnupg lsb-release apt-transport-https software-properties-common
# curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
mkdir -m 0755 -p /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
mkdir -m 0755 -p /etc/apt/keyrings \
&& curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] http://mirrors.aliyun.com/docker-ce/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
chmod a+r /etc/apt/keyrings/docker.gpg && apt-get update
apt-cache madison docker-ce # 查询存储库中可用的版本
apt-get install docker-ce=5:23.0.1-1~debian.11~bullseye # Docker守护进程
apt-get install docker-ce-cli=5:23.0.1-1~debian.11~bullseye # CLI工具用来远程控制Docker守护进程
# 轻松、高效的管理容器,它是一个用于定义和运行多容器 Docker 的应用程序工具
apt-get install docker-compose && apt-get install docker-compose-plugin
systemctl enable docker && systemctl restart docker && systemctl status docker
docker --version # 检查安装版本
docker info # 基本信息
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://lixing.5fl2j66y.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload && systemctl restart docker && docker info # 基本信息
Containerd通过在启动时指定一个配置文件夹,使后续所有镜像仓库相关的配置都可以在里面热加载,无需重启Containerd
# 若有 plugins."io.containerd.grpc.v1.cri".registry,则在下面添加 config_path = "/etc/containerd/certs.d"
# 若没有则可以在任意地方写入如下内容:
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
# 检查配置文件中是否有原有mirror相关的配置,如果有则需要以下删除配置
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://registry-1.docker.io"]
systemctl restart containerd # 重启Containerd,如果失败则执行 journalctl -u containerd 查看具体原因
# 在 config_path 路径中创建 docker.io/hosts.toml 文件,添加如下内容
server = "https://registry-1.docker.io"
[host."https://lixing.5fl2j66y.mirror.aliyuncs.com"]
capabilities = ["pull", "resolve", "push"]
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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/
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d5ccbe460a29 hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago pedantic_elgamal