Docker Engine安装

以Ubuntu为例,安装Docker Engine的要求:

  • Ubuntu 20版本以上
  • 64位操作系统
  1. 卸载已安装的版本

需要卸载的非官方包包括:

  • docker.io
  • docker-compose
  • docker-doc
  • podman-docke

Docker Engine依赖containerdrunc,Docker Engine将这些依赖项捆绑为一个包:containerd.io。 如果以前已经安装过Containerd或者runc,需要将他们卸载掉,以避免冲突问题的产生。

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
  1. 安装方式

可以使用以下几中方式来安装Docker Engine:

  • Docker Engine与Docker Desktop for Linux捆绑在一起。这是最简单和最快的入门方式。
  • 从Docker的apt存储库设置和安装Docker Engine。
  • 手动安装并手动管理升级。
  • 使用方便的脚本,仅推荐用于测试和开发环境。
  1. 使用Repository方式安装

    在首次在新的主机上安装Docker Engine之前,您需要设置Docker仓库。之后,您可以从仓库安装和更新Docker。

(1)更新apt软件包索引并安装软件包,以使apt能够通过HTTPS使用存储库

 sudo apt-get update
 sudo apt-get install ca-certificates curl gnupg

(2)添加Docker官方的GPG密钥

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

(3)使用以下命令设置仓库

 echo \
  deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo $VERSION_CODENAME) stable | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

(4)安装Docker Engine

sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

## 启动容器
sudo service docker start 
## 运行应用
sudo docker run hello-world

执行结果如下:

mypc@DESKTOP-ICS4DK7:~$ sudo docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:a13ec89cdf897b3e551bd9f89d499db6ff3a7f44c5b9eb8bca40da20eb4ea1fa
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
  3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注