不安分的黑娃
踏踏实实,坚持学习,慢慢就懂了~

参考资料

  1. Ubuntu安装Docker 官方文档: https://docs.docker.com/engine/install/ubuntu/

安装 Docker Engine

Ubuntu 安装

1. 通过仓库安装

1.1. 移除旧版本
sudo apt-get remove docker docker-engine docker.io containerd runc

支持的存储驱动
overlay2(默认), aufs , btrfs

1.2 配置仓库
sudo apt-get update

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

1.3. 添加 GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

1.4. 配置稳定版仓库
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
1.5. 安装 Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

结果:

public@public:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  cmake-data libjsoncpp1 librhash0 libuv1 linux-hwe-5.4-headers-5.4.0-90
  linux-hwe-5.4-headers-5.4.0-91 linux-hwe-5.4-headers-5.4.0-92
  linux-hwe-5.4-headers-5.4.0-94 linux-hwe-5.4-headers-5.4.0-96
  linux-hwe-5.4-headers-5.4.0-97 linux-hwe-5.4-headers-5.4.0-99
  mongodb-mongosh
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following packages will be upgraded:
  containerd.io docker-ce docker-ce-cli
3 upgraded, 0 newly installed, 0 to remove and 30 not upgraded.
Need to get 86.8 MB of archives.
After this operation, 684 kB of additional disk space will be used.
Get:1 https://download.docker.com/linux/ubuntu bionic/stable amd64 containerd.io amd64 1.5.10-1 [24.9 MB]
Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-cli amd64 5:20.10.13~3-0~ubuntu-bionic [41.0 MB]                                                                                     
Get:3 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 5:20.10.13~3-0~ubuntu-bionic [20.9 MB]                                                                                         
Fetched 86.8 MB in 31s (2,808 kB/s)                                                                                                                                                                               
(Reading database ... 376529 files and directories currently installed.)
Preparing to unpack .../containerd.io_1.5.10-1_amd64.deb ...
Unpacking containerd.io (1.5.10-1) over (1.4.12-1) ...
Preparing to unpack .../docker-ce-cli_5%3a20.10.13~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.13~3-0~ubuntu-bionic) over (5:20.10.12~3-0~ubuntu-bionic) ...
Preparing to unpack .../docker-ce_5%3a20.10.13~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce (5:20.10.13~3-0~ubuntu-bionic) over (5:20.10.12~3-0~ubuntu-bionic) ...
Setting up containerd.io (1.5.10-1) ...
Installing new version of config file /etc/containerd/config.toml ...
Setting up docker-ce-cli (5:20.10.13~3-0~ubuntu-bionic) ...
Setting up docker-ce (5:20.10.13~3-0~ubuntu-bionic) ...
Processing triggers for systemd (237-3ubuntu10.53) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...

安装指定版本的 Docker

  1. 列举仓库中可用的 Docker 版本
apt-cache madison docker-ce

结果如下:

 docker-ce | 5:20.10.13~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.12~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.11~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 ....
  1. 安装指定版本的 docker
    比如,我安装 5:20.10.133-0ubuntu-bionic
sudo apt-get install docker-ce=5:20.10.13~3-0~ubuntu-bionic docker-ce-cli=5:20.10.13~3-0~ubuntu-bionic containerd.io
1.5 验证

命令:

 sudo docker run hello-world

控制台输出:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:f861ba8563637d693e3043069b0a4ebf3d92c2e865b541379f6a6b8164b7c8bb
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/

2. 通过安装包安装

2.1. 下载安装包

访问 https://download.docker.com/linux/ubuntu/dists/, 选择自己的操作系统版本,我的是 18.04 对应是bionic;
然后访问 https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/ 下载对应的 .deb 文件.

有以下几类文件:
containerd.io_1.5.10-1_amd64.deb
docker-ce-cli_20.10.93-0ubuntu-bionic_amd64.deb
docker-ce-rootless-extras_20.10.93-0ubuntu-bionic_amd64.deb
docker-ce_20.10.93-0ubuntu-bionic_amd64.deb
docker-compose-plugin_2.3.3~ubuntu-bionic_amd64.deb
docker-scan-plugin_0.17.0~ubuntu-bionic_amd64.deb

2.2. 安装安装包
sudo dpkg -i 下载好的deb文件
2.3. 验证
sudo docker run hello-world

如何卸载 Docker ?

  1. 卸载 docker-ce docker-ce-cli containerd.io
    命令:
sudo apt-get purge docker-ce docker-ce-cli containerd.io
  1. 删除所有的容器,镜像和卷
 sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd
posted on 2022-03-18 15:35  不安分的黑娃  阅读(120)  评论(0编辑  收藏  举报