♣️

ubuntu docker安装

  1. 卸载历史版本冲突的配置信息
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
  1. Install using the apt repository, Set up Docker's apt repository.
    1. # Add Docker's official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl 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 # Add the repository to Apt sources: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
  1. Install the Docker packages.To install the latest version, run
    1. sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
      特定版本
      # List the available versions: apt-cache madison docker-ce | awk '{ print $3 }' 5:27.4.0-1~ubuntu.24.04~noble 5:27.3.1-1~ubuntu.24.04~noble ...
      VERSION_STRING=5:27.4.0-1~ubuntu.24.04~noble sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
  1. 验证安装结果
    1. sudo docker run hello-world
  1. 设置开机启动
    1. sudo systemctl enable docker
  1. 设置工作目录,配置镜像加速
    1. touch /etc/docker/daemon.json
      { "data-root": "/mnt/mydisk/docker", "registry-mirrors": ["https://mo4x3llw.mirror.aliyuncs.com"] }
      加载配置
      sudo systemctl daemon-reload
      sudo systemctl restart docker