Ubuntu安装Docker记录(基于阿里云)

安装 Docker

下面安装过程中,我同时放上 Docker 官方的安装源和证书、已经阿里云的安装源和证书,同志们任选其一即可,个人推荐国内环境使用阿里云的。

  1. 卸载旧版本

    bash 复制代码
    sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)
  2. 下载依赖

    bash 复制代码
    sudo apt update
    sudo apt install ca-certificates curl
  3. 下载 Docker 证书

    Docker 官方证书下载(下载后的证书存放在 /etc/apt/keyrings/docker.asc):

    bash 复制代码
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc

    阿里云证书下载 :(下载后的证书存放在 /etc/apt/keyrings/docker_aliyun.asc

    bash 复制代码
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker_aliyun.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
  4. 添加 docker 镜像源链接到 apt 源

    Docker 官方源添加(APT 被存放在 /etc/apt/sources.list.d/docker.sources

    bash 复制代码
    # Add the repository to Apt sources:
    sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
    Types: deb
    URIs: https://download.docker.com/linux/ubuntu
    Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
    Components: stable
    Signed-By: /etc/apt/keyrings/docker.asc
    EOF

    阿里云源添加 (APT 被存放在 /etc/apt/sources.list.d/docker_aliyun.sources

    bash 复制代码
    # Add the repository to Apt sources:
    sudo tee /etc/apt/sources.list.d/docker_aliyun.sources <<EOF
    Types: deb
    URIs: https://mirrors.aliyun.com/docker-ce/linux/ubuntu
    Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
    Components: stable
    Signed-By: /etc/apt/keyrings/docker_aliyun.asc
    EOF

    Signed-By: /etc/apt/keyrings/docker_aliyun.asc 指定前面拉取的证书位置

  5. 更新 APT 包索引

    bash 复制代码
    sudo apt-get update
  6. 安装最新的 docker 和及其相关组件

    bash 复制代码
    sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  7. 安装完成后可以通过

    bash 复制代码
    sudo systemctl status docker

    查看 Docker 是否运行,如果没有运行,可以通过

    bash 复制代码
    sudo systemctl start docker

    启动 docker 服务,如图为正常运行的截图:

更换镜像源

镜像推荐参考这篇 2026 最新 Docker 国内镜像源加速列表(1月10日更新)

个人推荐大家可以使用 轩辕镜像,付费的话 50G 7元的套餐版本,流量有效期一年,绝大多数人都够用了!

里面的镜像还是比较完善的!

  1. 更换国内镜像(轩辕有私有的专属域链接,大家可以自行添加自己的到 registry-mirrors 下面,非广告)。

    下面使用都是一些免费的镜像,供大伙参考,镜像配置文件存放在 /etc/docker/daemon.json

    bash 复制代码
    sudo tee /etc/docker/daemon.json <<EOF
    {
        "data-root": "/docker",
        "registry-mirrors": [
            "https://docker.nju.edu.cn",
            "https://docker.xuanyuan.me",
            "https://mirror.ccs.tencentyun.com"
        ],
        "insecure-registries": [
            "docker.xuanyuan.me"
        ]
    }
    EOF
    sudo systemctl daemon-reload
  2. 重启 docker

    bash 复制代码
    sudo systemctl stop docker
    sudo systemctl start docker
  3. 下载 hello_world 镜像进行测试

    bash 复制代码
    sudo docker run hello-world

参考资料

官方文档
参考文章

相关推荐
曾小蛙1 小时前
【TWIST2】 PICO重映射G1在ubuntu 22.04下环境配置
ubuntu·g1·twist2·gmr2·pico4u·xrobotoolkit
我是谁??1 小时前
ubuntu22.04 通过docker部署vLLM(Qwen3-0.6B)大模型+New API+OpenWebUI
docker·容器·vllm
starvapour1 小时前
Ubuntu部署gitlab频繁出现502的问题
linux·ubuntu·gitlab
运维瓦工2 小时前
DevOps 生态介绍(十):Docker Compose 核心 YAML 配置详解与常用命令大全
spring cloud·docker·容器
云烟成雨TD2 小时前
Spring AI 1.x 系列【59】容器化开发支持:Docker Compose 与 Testcontainers
人工智能·spring·docker
Plastic garden2 小时前
K8s(10)NFS 的动态 PV 创建数据库给k8s的mysql和redis
docker·容器·kubernetes
与海boy3 小时前
docker compose minio
docker·容器·eureka
__Witheart__3 小时前
rk3568 交叉编译链
ubuntu·rockchip
JimCarter3 小时前
使用Azure Devops Pipeline将Docker应用部署到你的Raspberry Pi上
docker·azure·树莓派·devops·orangepi·香橙派·raspberrypi