如何在 Ubuntu 20.04 上安装 Docker?

如何在 Ubuntu 20.04 上安装 Docker?

我花了一整天时间尝试安装 Docker,但我认为我的系统存在一些问题,导致无法正确安装和配置它。以下是我正在尝试安装的 Docker 的规格、我的 Ubuntu 系统以及我尝试过的方法...

眼镜:

  • 描述:Ubuntu 20.04.2 LTS
  • 代号:Focal
  • Docker 版本 20.10.5,内部版本 55c4c88

我尝试过的方法:
我按照 Docker 提供的安装文档进行操作(https://docs.docker.com/engine/install/ubuntu/)。我尝试了列出的所有方法,并且总是能够找到我认为已安装 Docker 的位置,但它总是无法启动。运行时,journalctl -xe我发现它出现错误“无法启动 Docker 应用程序容器引擎”。

当按照 Docker 列出的“使用存储库安装”方法运行时,sudo apt-get install docker-ce docker-ce-cli containerd.io我收到下面提供的输出...

Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
invoke-rc.d: initscript docker, action "start" failed.
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2021-04-10 14:04:01 CDT; 6ms ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
    Process: 30954 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
   Main PID: 30954 (code=exited, status=1/FAILURE)
dpkg: error processing package docker-ce (--configure):
 installed docker-ce package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of docker-ce-rootless-extras:
 docker-ce-rootless-extras depends on docker-ce; however:
  Package docker-ce is not configured yet.

dpkg: error processing package docker-ce-rootless-extras (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 docker-ce
 docker-ce-rootless-extras
E: Sub-process /usr/bin/dpkg returned an error code (1)

我也尝试过运行sudo dockerd,当我运行该命令时我收到此输出......

INFO[2021-04-10T14:07:34.379732477-05:00] Starting up                                  
INFO[2021-04-10T14:07:34.380601807-05:00] detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv.conf 
INFO[2021-04-10T14:07:34.381241252-05:00] parsed scheme: "unix"                         module=grpc
INFO[2021-04-10T14:07:34.381264907-05:00] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2021-04-10T14:07:34.381300038-05:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2021-04-10T14:07:34.381314640-05:00] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2021-04-10T14:07:34.382840191-05:00] parsed scheme: "unix"                         module=grpc
INFO[2021-04-10T14:07:34.382879930-05:00] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2021-04-10T14:07:34.382919283-05:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2021-04-10T14:07:34.382932330-05:00] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2021-04-10T14:07:34.389949119-05:00] [graphdriver] using prior storage driver: overlay2 
WARN[2021-04-10T14:07:34.393356340-05:00] Your kernel does not support CPU realtime scheduler 
WARN[2021-04-10T14:07:34.393368396-05:00] Your kernel does not support cgroup blkio weight 
WARN[2021-04-10T14:07:34.393372980-05:00] Your kernel does not support cgroup blkio weight_device 
INFO[2021-04-10T14:07:34.393489826-05:00] Loading containers: start.                   
WARN[2021-04-10T14:07:34.394967395-05:00] Running modprobe bridge br_netfilter failed with message: modprobe: WARNING: Module br_netfilter not found in directory /lib/modules/5.8.0-48-generic
, error: exit status 1 
WARN[2021-04-10T14:07:34.398454303-05:00] Running iptables --wait -t nat -L -n failed with message: `modprobe: FATAL: Module ip_tables not found in directory /lib/modules/5.8.0-48-generic
iptables v1.8.4 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.`, error: exit status 3 
INFO[2021-04-10T14:07:34.510702953-05:00] stopping event stream following graceful shutdown  error="<nil>" module=libcontainerd namespace=moby
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: modprobe: FATAL: Module ip_tables not found in directory /lib/modules/5.8.0-48-generic
iptables v1.8.4 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
 (exit status 3)

格式不好,请见谅...如果有人有提示,我将不胜感激!如果有一些日志/代码有助于故障排除,请告诉我!

答案1

此错误与未加载有关内核模块在这种情况下ip_tables

解决这些问题的推荐方法如下

  1. 简单重启(这能解决多少问题真是令人惊讶)
  2. 进行升级 ( sudo apt-get update && sudo apt-get upgrade)
  3. 强制加载内核模块

摘自回答

sudo modprobe ip_tables
sudo echo 'ip_tables' >> /etc/modules
  1. 如果你在提供商处托管你的服务器,请检查提供商是否事先修改了内核;或者如果你在 VPS 上运行,请检查你没有运行OpenDZ限制非常严格的 VPS

答案2

我能够通过重新安装操作系统(Ubuntu-Server)解决该问题。

相关内容