麦克斯仇
Think different
160
文章
41813
阅读
首页
INDEX
文章
ARTICLE
关于
ABOUT
Debian 安装 Docker-CE
创建日期:
2023/05/25
修改日期:
2025/01/05
Linux
Docker
- 官方教程:[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 for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt-get remove $pkg; done ``` ### 设置存储库 #### 更新 apt 包并安装依赖 ```bash apt-get update apt-get install -y ca-certificates curl gnupg ``` #### 添加 Docker 的密钥 ```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 # 清华 curl -fsSL https://mirror.tuna.tsinghua.edu.cn/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 # 清华源 echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/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 -y 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 ``` #### 更新版本 命令同安装命令 ### 开启 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/ ```
147
全部评论