安装Docker
docker官网:https://docs.docker.com/
docker中文:https://docs.docker.net.cn/
更新源和软件包
sudo apt update # 更新源 sudo apt upgrade # 更新软件包 # 也可以用以下方式自动更新源和软件包 sudo apt update && sudo apt upgrade -y
运行以下命令以卸载所有冲突的软件包(官方文档)
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
设置docker仓库(官方文档)
# 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
安装docker包(官方文档)
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
测试安装是否成功(官方文档)
sudo docker run hello-world # 国内拉取可能会失败
输出(#号后面的译文来源于chatGLM)
Unable to find image 'hello-world:latest' locally # 在本地找不到镜像 'hello-world:latest' latest: Pulling from library/hello-world # latest: 正从 library/hello-world 拉取 e6590344b1a5: Pull complete # e6590344b1a5: 拉取完成 Digest: sha256:424f1f86cdf501deb591ace8d14d2f40272617b51b374915a87a2886b2025ece # 摘要: sha256:424f1f86cdf501deb591ace8d14d2f40272617b51b374915a87a2886b2025ece Status: Downloaded newer image for hello-world:latest # 状态: 已下载较新的镜像 hello-world:latest Hello from Docker! # 来自 Docker 的问候! This message shows that your installation appears to be working correctly. # 此消息表明您的安装似乎正在正确工作。 To generate this message, Docker took the following steps: # 为了生成此消息,Docker 执行了以下步骤: 1. The Docker client contacted the Docker daemon. # 1. Docker 客户端联系了 Docker 守护进程。 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. # 2. Docker 守护进程从 Docker Hub 拉取了 "hello-world" 镜像。 (amd64) # (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. # 3. Docker 守护进程从该镜像创建了一个新容器,该容器运行生成您当前正在阅读的输出的可执行文件。 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. # 4. Docker 守护进程将输出流式传输到 Docker 客户端,客户端将其发送到您的终端。 To try something more ambitious, you can run an Ubuntu container with: docker run -it ubuntu bash # 要尝试更具挑战性的事情,您可以运行一个带有 bash 的 Ubuntu 容器: # docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ # 使用免费的 Docker ID 分享镜像、自动化工作流程等: # https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ # 更多示例和想法,请访问: # https://docs.docker.com/get-started/
看到以上表示安装成功。