国外版教程见官方文档:https://docs.docker.com/engine/install/debian/
系统环境
debian11
1 2 3 4 5 6 7 8 9 10 11
| > cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/
|
使用 apt 源进行安装
提示
debian12 安装见华为云官方文档
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| sudo apt-get update sudo apt-get install ca-certificates curl gnupg software-properties-common sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://mirrors.huaweicloud.com/docker-ce/linux/debian/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors.huaweicloud.com/docker-ce/linux/debian $(lsb_release -cs) stable"
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -cs) stable"
sudo apt-get update
|
安装 docker-ce
1 2 3
| apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
docker -v
|
配置 docker 国内镜像和参数设置
提示
2024.6 国内镜像加速服务一夜之间全被干掉了(🤣 我们 XX 真是太自信、太伟大了)
请自建镜像加速服务,可参考
https://github.com/dqzboy/Docker-Proxy > https://github.com/motao123/built-docker
阿里云 docker 镜像控制台地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
1
| vim /etc/docker/daemon.json
|
添加下面内容到 daemon.json 中
1 2 3 4 5 6 7 8 9 10
| { "registry-mirrors": [ "你的加速服务地址" ], "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } }
|
- registry-mirrors 中配置了 docker 镜像加速地址
- log-driver 设置将日志写入 json-file,默认值
- log-opts 设置了日志大小,max-size=10m,意味着一个容器日志大小上限是 10M, max-file=3,意味着一个容器有三个日志,分别是 id+.json、id+1.json、id+2.json
设置完成后重启 docker
1 2 3
| systemctl restart docker
docker info
|
拉取个镜像测试
1 2 3 4
| time docker pull nginx:latest
docker run --rm nginx:latest
|
安装 docker-compose(可选)
如果安装了 docker-compose-plugin 的话就不需要安装这个了,此外由于网络问题,国内下载不下来的话需要手动下载并上传到服务器上,自行替换最新版本
1 2 3 4
| sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
docker-compose --help
|