欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

在 Ubuntu 20.04 上学习如何安装和使用 Docker

最编程 2024-01-01 18:20:11
...
<pre><font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo apt update [sudo] libin 的密码: 命中:1 http://dl.google.com/linux/chrome/deb stable InRelease 命中:2 http://cn.archive.ubuntu.com/ubuntu focal InRelease 获取:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] 获取:4 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] 命中:5 http://ppa.launchpad.net/git-core/ppa/ubuntu focal InRelease<font color="#C4A000"> </font> 获取:6 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] 忽略:7 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal InRelease<font color="#C4A000"> </font> 获取:8 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [283 kB] 错误:9 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release<font color="#C4A000"> </font> 404 Not Found [IP: 91.189.95.85 80] 获取:10 http://cn.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [504 B] 获取:11 http://cn.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [363 kB] 获取:12 http://cn.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B] 获取:13 http://cn.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [10.4 kB] 获取:14 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [29.0 kB]<font color="#C4A000"> </font> 获取:15 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [63.9 kB] 获取:16 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B] 正在读取软件包列表... 完成<font color="#C4A000"> </font> <font color="#CC0000"><b>E: </b></font>仓库 “http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release” 没有 Release 文件。 <font color="#C4A000">N: </font>无法安全地用该源进行更新,所以默认禁用该源。 <font color="#C4A000">N: </font>参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。 <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 ca-certificates 已经是最新版 (20210119~20.04.2)。 ca-certificates 已设置为手动安装。 software-properties-common 已经是最新版 (0.98.9.5)。 software-properties-common 已设置为手动安装。 下列软件包是自动安装的并且现在不需要了: chromium-codecs-ffmpeg-extra gstreamer1.0-vaapi libgstreamer-plugins-bad1.0-0 libva-wayland2 linux-headers-5.11.0-27-generic linux-hwe-5.11-headers-5.11.0-27 linux-image-5.11.0-27-generic linux-modules-5.11.0-27-generic linux-modules-extra-5.11.0-27-generic linux-objects-nvidia-470-5.11.0-27-generic linux-signatures-nvidia-5.11.0-27-generic 使用&apos;sudo apt autoremove&apos;来卸载它(它们)。 下列【新】软件包将被安装: apt-transport-https curl gnupg-agent 升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 41 个软件包未被升级。 需要下载 171 kB 的归档。 解压缩后会消耗 620 kB 的额外空间。 您希望继续执行吗? [Y/n] y 获取:1 http://cn.archive.ubuntu.com/ubuntu focal-updates/universe amd64 apt-transport-https all 2.0.6 [4,680 B] 获取:2 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 curl amd64 7.68.0-1ubuntu2.7 [161 kB] 获取:3 http://cn.archive.ubuntu.com/ubuntu focal-updates/universe amd64 gnupg-agent all 2.2.19-3ubuntu2.1 [5,232 B] 已下载 171 kB,耗时 5秒 (31.3 kB/s)<font color="#C4A000"> </font> 正在选中未选择的软件包 apt-transport-https。 (正在读取数据库 ... 系统当前共安装有 256822 个文件和目录。) 准备解压 .../apt-transport-https_2.0.6_all.deb ... 正在解压 apt-transport-https (2.0.6) ... 正在选中未选择的软件包 curl。 准备解压 .../curl_7.68.0-1ubuntu2.7_amd64.deb ... 正在解压 curl (7.68.0-1ubuntu2.7) ... 正在选中未选择的软件包 gnupg-agent。 准备解压 .../gnupg-agent_2.2.19-3ubuntu2.1_all.deb ... 正在解压 gnupg-agent (2.2.19-3ubuntu2.1) ... 正在设置 apt-transport-https (2.0.6) ... 正在设置 gnupg-agent (2.2.19-3ubuntu2.1) ... 正在设置 curl (7.68.0-1ubuntu2.7) ... 正在处理用于 man-db (2.9.1-1) 的触发器 ... <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot; 获取:1 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB] 命中:2 http://dl.google.com/linux/chrome/deb stable InRelease 命中:3 http://cn.archive.ubuntu.com/ubuntu focal InRelease 获取:4 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [11.6 kB] 命中:5 http://ppa.launchpad.net/git-core/ppa/ubuntu focal InRelease 命中:6 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease 命中:7 http://security.ubuntu.com/ubuntu focal-security InRelease 命中:8 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease 忽略:9 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal InRelease 错误:10 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release 404 Not Found [IP: 91.189.95.85 80] 正在读取软件包列表... 完成 E: 仓库 “http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release” 没有 Release 文件。 N: 无法安全地用该源进行更新,所以默认禁用该源。 N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。 <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot; 命中:1 https://download.docker.com/linux/ubuntu focal InRelease 命中:2 http://dl.google.com/linux/chrome/deb stable InRelease 命中:3 http://security.ubuntu.com/ubuntu focal-security InRelease 命中:4 http://ppa.launchpad.net/git-core/ppa/ubuntu focal InRelease 命中:5 http://cn.archive.ubuntu.com/ubuntu focal InRelease 命中:6 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease 命中:7 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease 忽略:8 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal InRelease 错误:9 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release 404 Not Found [IP: 91.189.95.85 80] 正在读取软件包列表... 完成 E: 仓库 “http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release” 没有 Release 文件。 N: 无法安全地用该源进行更新,所以默认禁用该源。 N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。 <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo apt update 命中:1 http://dl.google.com/linux/chrome/deb stable InRelease 命中:2 https://download.docker.com/linux/ubuntu focal InRelease <font color="#C4A000"> </font> 命中:3 http://ppa.launchpad.net/git-core/ppa/ubuntu focal InRelease<font color="#C4A000"> </font> 命中:4 http://cn.archive.ubuntu.com/ubuntu focal InRelease<font color="#C4A000"> </font> 命中:5 http://security.ubuntu.com/ubuntu focal-security InRelease 命中:6 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease 忽略:7 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal InRelease 命中:8 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease 错误:9 http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release 404 Not Found [IP: 91.189.95.85 80] 正在读取软件包列表... 完成<font color="#C4A000"> </font> <font color="#CC0000"><b>E: </b></font>仓库 “http://ppa.launchpad.net/wine/wine-builds/ubuntu focal Release” 没有 Release 文件。 <font color="#C4A000">N: </font>无法安全地用该源进行更新,所以默认禁用该源。 <font color="#C4A000">N: </font>参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。 <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo apt install docker-ce docker-ce-cli containerd.io 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 下列软件包是自动安装的并且现在不需要了: chromium-codecs-ffmpeg-extra gstreamer1.0-vaapi libgstreamer-plugins-bad1.0-0 libva-wayland2 linux-headers-5.11.0-27-generic linux-hwe-5.11-headers-5.11.0-27 linux-image-5.11.0-27-generic linux-modules-5.11.0-27-generic linux-modules-extra-5.11.0-27-generic linux-objects-nvidia-470-5.11.0-27-generic linux-signatures-nvidia-5.11.0-27-generic 使用&apos;sudo apt autoremove&apos;来卸载它(它们)。 将会同时安装下列软件: docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns 建议安装: aufs-tools cgroupfs-mount | cgroup-lite 下列【新】软件包将被安装: containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns 升级了 0 个软件包,新安装了 7 个软件包,要卸载 0 个软件包,有 41 个软件包未被升级。 需要下载 95.6 MB 的归档。 解压缩后会消耗 403 MB 的额外空间。 您希望继续执行吗? [Y/n] y 获取:1 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.4.11-1 [23.7 MB] 获取:2 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB] 获取:3 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB] 获取:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:20.10.9~3-0~ubuntu-focal [38.8 MB] 获取:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.9~3-0~ubuntu-focal [21.2 MB] 获取:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.9~3-0~ubuntu-focal [7,914 kB] 获取:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.8.0~ubuntu-focal [3,889 kB] 已下载 95.6 MB,耗时 51秒 (1,867 kB/s) 正在选中未选择的软件包 pigz。 (正在读取数据库 ... 系统当前共安装有 256837 个文件和目录。) 准备解压 .../0-pigz_2.4-1_amd64.deb ... 正在解压 pigz (2.4-1) ... 正在选中未选择的软件包 containerd.io。 准备解压 .../1-containerd.io_1.4.11-1_amd64.deb ... 正在解压 containerd.io (1.4.11-1) ... 正在选中未选择的软件包 docker-ce-cli。 准备解压 .../2-docker-ce-cli_5%3a20.10.9~3-0~ubuntu-focal_amd64.deb ... 正在解压 docker-ce-cli (5:20.10.9~3-0~ubuntu-focal) ... 正在选中未选择的软件包 docker-ce。 准备解压 .../3-docker-ce_5%3a20.10.9~3-0~ubuntu-focal_amd64.deb ... 正在解压 docker-ce (5:20.10.9~3-0~ubuntu-focal) ... 正在选中未选择的软件包 docker-ce-rootless-extras。 准备解压 .../4-docker-ce-rootless-extras_5%3a20.10.9~3-0~ubuntu-focal_amd64.deb ... 正在解压 docker-ce-rootless-extras (5:20.10.9~3-0~ubuntu-focal) ... 正在选中未选择的软件包 docker-scan-plugin。 准备解压 .../5-docker-scan-plugin_0.8.0~ubuntu-focal_amd64.deb ... 正在解压 docker-scan-plugin (0.8.0~ubuntu-focal) ... 正在选中未选择的软件包 slirp4netns。 准备解压 .../6-slirp4netns_0.4.3-1_amd64.deb ... 正在解压 slirp4netns (0.4.3-1) ... 正在设置 slirp4netns (0.4.3-1) ... 正在设置 docker-scan-plugin (0.8.0~ubuntu-focal) ... 正在设置 containerd.io (1.4.11-1) ... Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/co ntainerd.service. 正在设置 docker-ce-cli (5:20.10.9~3-0~ubuntu-focal) ... 正在设置 pigz (2.4-1) ... 正在设置 docker-ce-rootless-extras (5:20.10.9~3-0~ubuntu-focal) ... 正在设置 docker-ce (5:20.10.9~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.soc ket. 正在处理用于 man-db (2.9.1-1) 的触发器 ... 正在处理用于 systemd (245.4-4ubuntu3.13) 的触发器 ... <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo systemctl status docker <font color="#4E9A06"><b>●</b></font> docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: <font color="#4E9A06"><b>active (running)</b></font> since Wed 2021-10-20 19:43:01 CST; 1min 4s ago TriggeredBy: <font color="#4E9A06"><b>●</b></font> docker.socket Docs: https://docs.docker.com Main PID: 109002 (dockerd) Tasks: 18 Memory: 31.9M CGroup: /system.slice/docker.service └─109002 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.540055411+08:00&quot; level=warning msg=&quot;Yo<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.540070677+08:00&quot; level=warning msg=&quot;Yo<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.540074934+08:00&quot; level=warning msg=&quot;Yo<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.540183994+08:00&quot; level=info msg=&quot;Loadi<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.597684235+08:00&quot; level=info msg=&quot;Defau<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.624409976+08:00&quot; level=info msg=&quot;Loadi<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.636398780+08:00&quot; level=info msg=&quot;Docke<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.636475816+08:00&quot; level=info msg=&quot;Daemo<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> 10月 20 19:43:01 oak systemd[1]: Started Docker Application Container Engine. 10月 20 19:43:01 oak dockerd[109002]: time=&quot;2021-10-20T19:43:01.652738445+08:00&quot; level=info msg=&quot;API l<span style="background-color:#FFFFFF"><font color="#300A24">&gt;</font></span> <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo usermod -aG docker $USER <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ docker container run hello-world docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post &quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create&quot;: dial unix /var/run/docker.sock: connect: permission denied. See &apos;docker run --help&apos;. <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ docker ps Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get &quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json&quot;: dial unix /var/run/docker.sock: connect: permission denied <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo chmod 666 /var/run/docker.sock <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ docker container run hello-world Unable to find image &apos;hello-world:latest&apos; locally latest: Pulling from library/hello-world 2db29710123e: Pulling fs layer docker: error pulling image configuration: Get &quot;https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/fe/feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412/data?verify=1634733430-VmtIwrU5jr5B8Ukm8s2XoZeZNlo%3D&quot;: dial tcp: lookup production.cloudflare.docker.com: Temporary failure in name resolution. See &apos;docker run --help&apos;. <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo setfacl --modify user::rw /var/run/docker.sock <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ docker container run hello-world Unable to find image &apos;hello-world:latest&apos; locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51 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 &quot;hello-world&quot; 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/ <font color="#4E9A06"><b>libin@oak</b></font>:<font color="#3465A4"><b>~</b></font>$ </pre>

推荐阅读