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

简介: 如何在 Ubuntu 20.04 上安装和使用 Docker

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


Docker 是一个开源的容器化平台,它允许你构建,测试,并且作为可移动的容器去部署应用,这些容器可以在任何地方运行。一个容器表示一个应用的运行环境,并且包含软件运行所需要的所有依赖软件。


Docker 是现代软件开发,持续集成,持续交付的一部分。


这篇教程将会涉及如何在 Ubuntu 上安装 Docker。


Docker 在标准的 Ubuntu 20.04 软件源中可用,但是可能不是最新的版本。我们将会从 Docker 的官方软件源中安装最新的 Docker 软件包。


一、在 Ubuntu 20.04 上安装 Docker


在 Ubuntu 上安装 Docker 非常直接。我们将会启用 Docker 软件源,导入 GPG key,并且安装软件包。


首先,更新软件包索引,并且安装必要的依赖软件,来添加一个新的 HTTPS 软件源:


sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-propertie

使用下面的 curl 导入源仓库的 GPG key:


curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -


将 Docker APT 软件源添加到你的系统:


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

现在,Docker 软件源被启用了,你可以安装软件源中任何可用的 Docker 版本。

01.想要安装 Docker 最新版本,运行下面的命令。如果你想安装指定版本,跳过这个步骤,并且跳到下一步。


sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io


02.想要安装指定版本,首先列出 Docker 软件源中所有可用的版本:


sudo apt update
apt list -a docker-ce



可用的 Docker 版本将会在第二列显示。在写作这篇文章的时候,在官方 Docker 软件源中只有一个 Docker 版本(5:19.03.9~3-0~ubuntu-focal)可用:


docker-ce/focal 5:19.03.9~3-0~ubuntu-focal amd64

通过在软件包名后面添加版本=<VERSION>来安装指定版本:


sudo apt install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io


一旦安装完成,Docker 服务将会自动启动。你可以输入下面的命令,验证它:


sudo systemctl status docker


输出将会类似下面这样:


● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-05-21 14:47:34 UTC; 42s ago
...


当一个新的 Docker 发布时,你可以使用标准的sudo apt update && sudo apt upgrade流程来升级 Docker 软件包。

如果你想阻止 Docker 自动更新,锁住它的版本:


sudo apt-mark hold docker-ce


二、以非 Root 用户身份执行 Docker


默认情况下,只有 root 或者 有 sudo 权限的用户可以执行 Docker 命令。


想要以非 root 用户执行 Docker 命令,你需要将你的用户添加到 Docker 用户组,该用户组在 Docker CE 软件包安装过程中被创建。想要这么做,输入:


sudo usermod -aG docker $USER


$USER是一个环境变量,代表当前用户名。

登出,并且重新登录,以便用户组会员信息刷新。


三、验证安装过程


想要验证 Docker 是否已经成功被安装,你可以执行docker命令,前面不需要加`sudo, 我们将会运行一个测试容器:


docker container run hello-world


如果本地没有该镜像,这个命令将会下载测试镜像,在容器中运行它,打印出 “Hello from Docker”,并且退出。

输出看起来应该像这样:


0.png


这个容器将会在打印消息后停止运行,因为它没有任何长期运行的进程。

默认情况下,Docker 从 Docker Hub 拉取镜像。它是一个云端服务,主要用来储存 公有和私有源中的 Docker 镜像。


3.1如果 hello-world报错:


解决方案如下:

在尝试连接到 unix:///var/run/docker.sock 上的 Docker 守护进程套接字时获得权限被拒绝:获取 http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json:拨号 unix /var/run/docker.sock: 连接:权限被拒绝 docker 代码示例


示例 1:尝试连接到 Docker 守护进程套接字时权限被拒绝


sudo chmod 666 /var/run/docker.sock


示例2:containers/create:拨unix /var/run/docker.sock:connect:权限被拒绝


sudo setfacl --modify user::rw /var/run/docker.sock


四、卸载 Docker


在卸载 Docker 之前,你最好 移除所有的容器,镜像,卷和网络。

运行下面的命令停止所有正在运行的容器,并且移除所有的 docker 对象:


docker container stop $(docker container ls -aq)
docker system prune -a --volumes


现在你可以使用apt像卸载其他软件包一样来卸载 Docker:


sudo apt purge docker-ce
sudo apt autoremove


五、总结


我们已经向你展示如何在 Ubuntu 20.04 机器上安装 Docker。

想要学习更多关于 Docker 的信息,查阅官方 Docker 文档

附件:

命令行源码:


<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>
目录
相关文章
|
1月前
|
Ubuntu 安全 iOS开发
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for Ubuntu 24.04 - Nessus 自动化安装程序
130 5
|
1月前
|
NoSQL Ubuntu MongoDB
在Ubuntu 22.04上安装MongoDB 6.0的步骤
这些步骤应该可以在Ubuntu 22.04系统上安装MongoDB 6.0。安装过程中,如果遇到任何问题,可以查阅MongoDB的官方文档或者Ubuntu的相关帮助文档,这些资源通常提供了解决特定问题的详细指导。
227 18
|
2月前
|
关系型数据库 数据库 PostgreSQL
docker 安装 Postgres 17.6
本文介绍如何通过Docker安装和配置PostgreSQL 17.6。内容包括拉取镜像、导出配置文件、运行容器并挂载数据与配置文件目录,以及进入容器使用psql操作数据库的完整步骤,便于持久化管理和自定义配置。
350 3
docker 安装 Postgres 17.6
|
1月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
336 5
|
1月前
|
Java Linux 虚拟化
【Docker】(1)Docker的概述与架构,手把手带你安装Docker,云原生路上不可缺少的一门技术!
1. Docker简介 1.1 Docker是什么 为什么docker会出现? 假定您在开发一款平台项目,您的开发环境具有特定的配置。其他开发人员身处的环境配置也各有不同。 您正在开发的应用依赖于您当前的配置且还要依赖于某些配置文件。 您的企业还拥有标准化的测试和生产环境,且具有自身的配置和一系列支持文件。 **要求:**希望尽可能多在本地模拟这些环境而不产生重新创建服务器环境的开销 问题: 要如何确保应用能够在这些环境中运行和通过质量检测? 在部署过程中不出现令人头疼的版本、配置问题 无需重新编写代码和进行故障修复
328 2
|
2月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
220 18
|
2月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
246 15
|
2月前
|
存储 Ubuntu iOS开发
在Ubuntu 22.04系统上安装libimobiledevice的步骤
为了获取更多功能或者解决可能出现问题,请参考官方文档或者社区提供支持。
163 14
|
2月前
|
Ubuntu 安全 关系型数据库
安装与配置MySQL 8 on Ubuntu,包括权限授予、数据库备份及远程连接指南
以上步骤提供了在Ubuntu上从头开始设置、配置、授权、备份及恢复一个基础但完整的MySQL环境所需知识点。
401 7
|
2月前
|
消息中间件 人工智能 运维
Ubuntu环境下的 RabbitMQ 安装与配置详细教程
本文聚焦在Ubuntu下RabbitMQ安装与配置教程,旨在帮助读者快速构建稳定可用的消息队列服务。