京东云ubuntu安装docker?

云计算

在京东云的 Ubuntu 服务器上安装 Docker 非常简单。以下是详细的步骤,适用于京东云上的 Ubuntu 系统(如 Ubuntu 20.04 或 22.04)。


✅ 步骤一:更新系统包

sudo apt update && sudo apt upgrade -y

✅ 步骤二:安装必要的依赖包

sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release

✅ 步骤三:添加 Docker 的官方 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=$(dpkg --print-architecture) 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

注意:$(lsb_release -cs) 会自动获取你的 Ubuntu 版本代号(如 focaljammy),确保正确。


✅ 步骤五:更新软件包索引并安装 Docker

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

✅ 步骤六:验证 Docker 是否安装成功

sudo docker --version

输出类似:

Docker version 24.0.7, build afdd53b

还可以运行测试容器:

sudo docker run hello-world

如果看到欢迎信息,说明安装成功!


✅ (可选)配置非 root 用户使用 Docker

避免每次使用 sudo,可以将当前用户加入 docker 组:

sudo usermod -aG docker $USER

⚠️ 执行后需要 重新登录 或重启 shell 才能生效。

之后就可以直接使用:

docker run hello-world

无需 sudo


✅ (可选)设置 Docker 开机自启

sudo systemctl enable docker

启动/停止/重启 Docker 服务:

sudo systemctl start docker
sudo systemctl restart docker
sudo systemctl stop docker

💡 注意事项(京东云环境)

  1. 防火墙/安全组:京东云控制台中确保安全组规则允许你需要的端口(如 80、443、映射的容器端口等)。
  2. 内核版本:Ubuntu 一般自带兼容内核,无需额外升级。
  3. 镜像提速(推荐国内用户)
    由于 Docker 官方镜像拉取较慢,建议配置国内镜像提速器,如阿里云、腾讯云或中科大。

    编辑或创建 /etc/docker/daemon.json

    {
     "registry-mirrors": [
       "https://<your-mirror>.mirror.aliyuncs.com"
     ]
    }

    获取阿里云镜像提速地址(免费):
    登录 阿里云容器镜像服务 → 镜像工具 → 镜像提速器。

    修改后重启 Docker:

    sudo systemctl daemon-reload
    sudo systemctl restart docker

🎉 完成!

你现在已经在京东云的 Ubuntu 实例上成功安装并配置了 Docker,可以开始部署容器应用了!

如有其他需求(如安装 Docker Compose),也可以继续告诉我。

未经允许不得转载:CLOUD云枢 » 京东云ubuntu安装docker?