如何在 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>
目录
相关文章
|
5天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
54 25
|
22天前
|
关系型数据库 MySQL 数据库
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
122 42
|
15天前
|
监控 Linux PHP
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
65 20
|
26天前
|
Linux Docker 容器
安装docker-18.06报错Error: libseccomp conflicts with docker-18.06
通过这些步骤,您可以成功在CentOS上安装Docker 18.06,并解决libseccomp的冲突问题。这些方法确保系统兼容性,并保证Docker的正常运行。
60 27
|
15天前
|
Ubuntu API 网络虚拟化
ubuntu22 编译安装docker,和docker容器方式安装 deepseek
本脚本适用于Ubuntu 22.04,主要功能包括编译安装Docker和安装DeepSeek模型。首先通过Apt源配置安装Docker,确保网络稳定(建议使用VPN)。接着下载并配置Docker二进制文件,创建Docker用户组并设置守护进程。随后拉取Debian 12镜像,安装系统必备工具,配置Ollama模型管理器,并最终部署和运行DeepSeek模型,提供API接口进行交互测试。
241 15
|
14天前
|
消息中间件 Kafka Docker
docker compose 安装 kafka
通过本文的步骤,您可以快速在本地使用 Docker Compose 安装并配置 Kafka 和 Zookeeper。Docker Compose 简化了多容器应用的管理,方便快速搭建和测试分布式系统。
56 2
|
1月前
|
弹性计算 Ubuntu Java
OS-Copilot-ubuntu镜像版本的具体测试使用(安装方式有单独注明)
作为一名个人开发者,我主要负责云资源的运维和管理。在使用OS Copilot的过程中,我遇到了一些配置问题,特别是在ECS实例中设置AccessKey时,但最终成功解决了。通过使用OS Copilot的-t/-f/管道功能,我大大提升了效率,减少了命令编写的工作量,特别是在搭建Java运行环境时效果显著。此外,| 功能帮助我快速理解文档,整体体验非常流畅,推荐给其他开发者使用。
43 6
|
存储 Ubuntu Linux
【云原生 | 02】分别在CentOS、Ubuntu、macOS、win7、win8、win10等不同操作系统下安装Docker详细教程
Docker引擎是使用Docker容器的核心组件,可以在主流的操作系统和云平台上使用, 包括 Linux 操作系统(如 Ubuntu、Debian、CentOS、Redhat 等),macOS 和 Windows 操作系统, 以及IBM、亚马逊、微软等知名云平台.........
481 0
|
9月前
|
Ubuntu Docker 索引
ubuntu 20.04 安装docker教程和安装中遇到的问题解决方案(超详细 附加图文教程)
ubuntu 20.04 安装docker教程和安装中遇到的问题解决方案(超详细 附加图文教程)
1604 0