Debian11之Docker稳定版本安装

官方地址

卸载历史版本

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相关的文件

存储库安装

1、安装依赖包

apt-get update && apt-get install ca-certificates curl gnupg lsb-release apt-transport-https software-properties-common

2、安装GPG证书(使用阿里云地址)

  • docker地址
# 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
  • aliyun地址
# 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

3、写入软件源信息(使用阿里云地址)

  • docker地址
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
  • aliyun地址
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

4、安装 Docker

chmod a+r /etc/apt/keyrings/docker.gpg && apt-get update
apt-cache madison docker-ce # 查询存储库中可用的版本

Debian11之Docker稳定版本安装_第1张图片

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 # 基本信息

自定义阿里云镜像

登陆阿里云控制台

在这里插入图片描述
Debian11之Docker稳定版本安装_第2张图片
Debian11之Docker稳定版本安装_第3张图片

配置Docker运行时镜像加速器

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 # 基本信息

Debian11之Docker稳定版本安装_第4张图片

配置Containerd运行时镜像加速器

Containerd通过在启动时指定一个配置文件夹,使后续所有镜像仓库相关的配置都可以在里面热加载,无需重启Containerd

  • 编辑 /etc/containerd/config.toml 文件
# 若有 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

  • 运行 hello-world
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
  • 常用操作
    参考这篇文章

你可能感兴趣的:(容器运行时,Linux_Debian,debian)