Ubuntu server18、20、22安装、部署Docker

本文档提供了在Ubuntu上卸载旧版Docker并安装Docker-CE的完整流程,包括更新系统工具、添加GPG证书、设置软件源、安装Docker及相关依赖,以及安装Python3-pip和docker-compose。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我分别用18、20和最新的22测试过,都正常安装成功。

1、卸载旧版本

sudo apt-get remove docker docker-engine docker.io containerd runc

2、安装必要的一些系统工具

sudo apt-get update

sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common gnupg-agent

3、安装GPG证书

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

4、写入软件源信息

sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

5、更新并安装Docker-CE

sudo apt-get -y update

sudo apt-get install -y docker-ce docker-ce-cli containerd.io

sudo apt install -y python3-pip

sudo pip3 install docker-compose

### 安装部署 DockerUbuntu Server 20.04 上 #### 准备工作 为了确保系统的更新至最新状态,在安装任何新软件之前,建议先执行系统包管理器的刷新操作。 ```bash sudo apt update && sudo apt upgrade -y ``` #### 设置 Docker 的 APT 源 官方推荐通过设置特定源来获取最新的稳定版 Docker。这一步骤可以避免依赖默认仓库中的旧版本。 ```bash # 添加官方 GPG 密钥 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # 添加稳定的 Docker APT 源 echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ``` #### 更新本地APT索引并安装Docker引擎 完成上述配置之后,再次运行 `apt-get` 命令以同步新的存储库信息,并从中下载安装所需的文件。 ```bash sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io -y ``` 此时已经成功完成了 Docker Engine 的基本安装过程[^1]。 #### 验证安装成果 启动服务并且验证其正常运作: ```bash sudo systemctl start docker sudo systemctl enable docker docker run hello-world ``` 如果一切顺利的话,则会看到一条来自 Docker 的欢迎消息,表明容器环境已经被正确搭建起来。 #### 用户权限调整(可选) 为了让非root用户也能方便地管理和使用 Docker 资源,默认情况下需要将其加入到名为 `docker` 的组里去: ```bash sudo usermod -aG docker $USER newgrp docker ``` 注意:更改后的群组成员身份不会立即生效;通常重启计算机或者注销再登录一次即可解决这个问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值