侧边栏壁纸
博主头像
沙漠渔

把過去的累積,善用到當下

  • 累计撰写 484 篇文章
  • 累计创建 295 个标签
  • 累计收到 958 条评论
标签搜索

目 录CONTENT

文章目录

Ubuntu20.04 lts 安装docker的详细步骤

沙漠渔
2022-08-11 / 0 评论 / 0 点赞 / 1,269 阅读 / 6,664 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-08-11,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

最近新申请了一台服务器,要求安装的是Ubuntu 20.04,现在在开始配置环境。

前言

首先想着看看有没有安装docker,输入docker之后,出现如下信息:

~# docker

Command 'docker' not found, but can be installed with:

snap install docker     # version 20.10.14, or
apt  install docker.io  # version 20.10.12-0ubuntu2~20.04.1

See 'snap info docker' for additional versions.

看着提示内容可以使用 snap install docker安装version 20.10.14,于是就试了一下,结果装完之后感觉有点不对劲,多出来一堆/dev/loop*,不清楚是咋回事,并且还都占用100%,就查询了一下snap是啥东西,最后看到很多反馈有可能存在权限问题,最终决定放弃,使用正常的apt-get方式安装了。

安装所需包

终端输入:

~# sudo apt-get install apt-transport-https ca-certificates software-properties-common curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20211016~20.04.1).
curl is already the newest version (7.68.0-1ubuntu2.12).
software-properties-common is already the newest version (0.99.9.8).
apt-transport-https is already the newest version (2.0.9).
0 upgraded, 0 newly installed, 0 to remove and 45 not upgraded.

添加软件源

  • 官方的软件源,输入命令:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg|sudo apt-key add -
  • 国内的软件源,输入命令:
~# curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
OK

添加GPG密钥

使用官方的软件源,输入命令:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

使用国内的软件源,输入命令:

sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

执行结果如下:

~# sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Get:2 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal InRelease [57.7 kB]
Hit:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu focal-security InRelease
Get:6 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages [17.7 kB]
Fetched 75.4 kB in 2s (40.1 kB/s)
Reading package lists... Done

更新源数据

~# sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
Hit:4 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu focal-security InRelease
Reading package lists... Done

安装Docker-ce

输入命令:

sudo apt-get install docker-ce

执行结果如下:

~# sudo apt-get install docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  containerd.io docker-ce-cli docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
0 upgraded, 7 newly installed, 0 to remove and 45 not upgraded.
Need to get 102 MB of archives.
After this operation, 422 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:2 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 containerd.io amd64 1.6.7-1 [28.1 MB]
Get:3 http://mirrors.aliyun.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:4 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:20.10.17~3-0~ubuntu-focal [40.6 MB]
Get:5 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.17~3-0~ubuntu-focal [21.0 MB]
Get:6 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.17~3-0~ubuntu-focal [8,171 kB]
Get:7 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-focal [3,521 kB]
Fetched 102 MB in 11s (9,630 kB/s)
Selecting previously unselected package pigz.
(Reading database ... 71870 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.6.7-1_amd64.deb ...
Unpacking containerd.io (1.6.7-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../5-docker-scan-plugin_0.17.0~ubuntu-focal_amd64.deb ...
Unpacking docker-scan-plugin (0.17.0~ubuntu-focal) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../6-slirp4netns_0.4.3-1_amd64.deb ...
Unpacking slirp4netns (0.4.3-1) ...
Setting up slirp4netns (0.4.3-1) ...
Setting up docker-scan-plugin (0.17.0~ubuntu-focal) ...
Setting up containerd.io (1.6.7-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-ce-cli (5:20.10.17~3-0~ubuntu-focal) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-focal) ...
Setting up docker-ce (5:20.10.17~3-0~ubuntu-focal) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.15) ...

验证结果

直接输入docker --version出现异常情况:

~# docker --version
-bash: /snap/bin/docker: No such file or directory

发现还是去/snap/下找的docker,但是前面已经卸载了啊,

最后验证可以通过sudo docker --version验证最新安装的docker信息

~# sudo docker --version
Docker version 20.10.17, build 100c701

最后查看&PATH环境变量中,最后加入了/snap/bin,把这个环境变量去掉就可以了,验证正常。

~# docker --version
Docker version 20.10.17, build 100c701
0
广告 广告

评论区