Ubuntu Server 24.04 LTS 安装 Docker 与 Docker Compose

参考

环境

软件/系统 版本 说明
VMware Workstation 16 Pro 16.2.4 build-20089737
Ubuntu Server Ubuntu Server 24.04 LTS
net-tools 2.10-0.1ubuntu4 软件包 (查看虚拟机ip使用)
nano 7.2-2build1 软件包(编辑器)
apt-transport-https 2.7.14build2 软件包
curl 8.5.0-2ubuntu10.3 软件包
docker-ce 5:27.2.0-1 软件包
docker-ce-cli 5:27.2.0-1 软件包
containerd.io 1.7.21-1 软件包
docker-compose-plugin 2.29.2-1 软件包

正文

  1. 设置软件源为国内源(此处使用清华源)

    # 备份源
    sudo cp /etc/apt/sources.list.d/ubuntu.sources  /etc/apt/sources.list.d/ubuntu.sources.back
    # 编辑源
    sudo nano /etc/apt/sources.list.d/ubuntu.sources
    

    将下面的内容填充到 ubuntu.sources

    Types: deb
    URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    Suites: noble noble-updates noble-backports
    Components: main restricted universe multiverse
    Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    # Types: deb-src
    # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    # Suites: noble noble-updates noble-backports
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
    Types: deb
    URIs: http://security.ubuntu.com/ubuntu/
    Suites: noble-security
    Components: main restricted universe multiverse
    Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # Types: deb-src
    # URIs: http://security.ubuntu.com/ubuntu/
    # Suites: noble-security
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # 预发布软件源,不建议启用
    
    # Types: deb
    # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    # Suites: noble-proposed
    # Components: main restricted universe multiverse
    # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
    # # Types: deb-src
    # # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
    # # Suites: noble-proposed
    # # Components: main restricted universe multiverse
    # # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
    
  2. 更新软件包并安装必要软件

    由于备份了 ubuntu.sourcesubuntu.sources.back 所以后续执行 apt 相关命令时会提示N: Ignoring file 'ubuntu.sources.back' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension,忽视即可。

    sudo apt update
    sudo apt install apt-transport-https curl
    
  3. 导入阿里云官方 GPG 密钥

    curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    
  4. 添加阿里云源

    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  5. 更新源

    sudo apt update
    
  6. 安装

    sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
    
  7. 检查运行状态

    sudo systemctl is-active docker
    

    显示如下为正常

    active
    
  8. 设置 docker 开机启动

    systemctl enable docker.service
    
  9. 常用命令

posted @   夏秋初  阅读(1681)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示