Debian10 安装 Docker-CE
- 官方教程:[https://docs.docker.com/engine/install/debian/](https://docs.docker.com/engine/install/debian/) - 阿里教程:[https://developer.aliyun.com/article/110806](https://developer.aliyun.com/article/110806) 不推荐使用,仅用于获取阿里镜像地址 > 注:以下命令使用 `root` 账户 ### 如果之前安装过docker,请先卸载旧版本 ```bash apt-get remove docker docker.io containerd runc apt-get remove docker-engine ``` ### 设置存储库 #### 更新 `apt` 包索引并安装包以允许 `apt` 通过 `HTTPS` 使用存储库 ```bash apt-get update apt-get install ca-certificates curl gnupg ``` #### 添加 `Docker` 的官方 `GPG` 密钥 ```bash install -m 0755 -d /etc/apt/keyrings # 以下官方地址、阿里地址二选一,秘钥文件都是一样的 curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg chmod a+r /etc/apt/keyrings/docker.gpg ``` #### 设置存储库并更新缓存 设置源(二选一) ```bash # 官方源 echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ 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 \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ tee /etc/apt/sources.list.d/docker.list > /dev/null ``` 更新缓存 ```bash apt-get update ``` ### 安装 Docker-CE #### 安装最新版本 ```bash apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin ``` #### 安装指定版本 查看版本列表 ```bash apt-cache madison docker-ce | awk '{ print $3 }' ``` 查看到如下类似内容,存储库中列出可用版本 ``` 5:24.0.1-1~debian.10~buster 5:24.0.0-1~debian.10~buster 5:23.0.6-1~debian.10~buster 5:23.0.5-1~debian.10~buster ... 5:20.10.24~3-0~debian-buster 5:20.10.23~3-0~debian-buster 5:20.10.22~3-0~debian-buster ... ``` 选择所需版本并安装: ```bash VERSION_STRING=5:20.10.23~3-0~debian-bullseye apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin ``` #### 更新版本 命令同安装命令 ### 修改cgroupdriver & 修改日志文件记录方式 & 使用阿里容器镜像服务 `docker` 默认使用的文件驱动是 `cgroups` ,如果后期使用 `k8s` 时需要修改为 `Systemd` ,而且 `Systemd` 更强大 参考文档:[Cgroups 与 Systemd](https://www.cnblogs.com/sparkdev/p/9523194.html "Cgroups 与 Systemd") 日志文件官方教程:[JSON File logging driver](https://docs.docker.com/config/containers/logging/json-file/ "JSON File logging driver") `docker` 默认容器下载地址在国外,国内下载很慢,需要使用阿里源。阿里镜像服务官方地址(使用阿里云账号或淘宝账号登录):[容器镜像服务](https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors) > 这里提供我的阿里源地址: ```bash mkdir -p /etc/docker tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://0zlpdgww.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } } EOF systemctl daemon-reload ``` ### 开启 Docker 服务,开启开机自启 ```bash # 默认已启动,修改配置后需要重启 systemctl restart docker # 设置开机自启 systemctl enable docker ``` ### 运行 hello-world 验证是否正确安装 执行以下脚本 ```bash docker run hello-world ``` 查看到如下类似内容 ``` 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/ ```