无法在 Ubuntu 16.04 中启动 Docker 服务

Posted

技术标签:

【中文标题】无法在 Ubuntu 16.04 中启动 Docker 服务【英文标题】:Unable to start Docker Service in Ubuntu 16.04 【发布时间】:2016-09-10 16:11:28 【问题描述】:

我一直在尝试在 Ubuntu 16.04 上使用 Docker (1.10),但安装失败,因为 Docker 服务没有启动。 我已经尝试通过 docker.iodocker-engine apt 包和curl -sSL https://get.docker.com/ | sh 安装 docker,但它不起作用。

我的主机信息是:

Linux Xenial 4.5.3-040503-generic #201605041831 SMP Wed May 4 22:33:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

这里是systemctl status docker.service

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since sáb 2016-05-14 15:17:31 CEST; 12min ago
     Docs: https://docs.docker.com
  Process: 22479 ExecStart=/usr/bin/docker daemon -H fd:// (code=exited, status=1/FAILURE)
 Main PID: 22479 (code=exited, status=1/FAILURE)

may 14 15:17:30 Xenial docker[22479]: time="2016-05-14T15:17:30.103601523+02:00" level=info msg="New containerd process, pid: 22485\n"
may 14 15:17:31 Xenial docker[22479]: time="2016-05-14T15:17:31.149064723+02:00" level=error msg="devmapper: Unable to delete device: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool"
may 14 15:17:31 Xenial docker[22479]: time="2016-05-14T15:17:31.149127439+02:00" level=warning msg="devmapper: Usage of loopback devices is strongly discouraged for production use. Please use `--storage-opt dm.thinpooldev` or use `man docker` to refer to dm.thinpooldev section."
may 14 15:17:31 Xenial docker[22479]: time="2016-05-14T15:17:31.153010028+02:00" level=error msg="[graphdriver] prior storage driver \"devicemapper\" failed: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool"
may 14 15:17:31 Xenial docker[22479]: time="2016-05-14T15:17:31.153130839+02:00" level=fatal msg="Error starting daemon: error initializing graphdriver: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool"
may 14 15:17:31 Xenial systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
may 14 15:17:31 Xenial docker[22479]: time="2016-05-14T15:17:31+02:00" level=info msg="stopping containerd after receiving terminated"
may 14 15:17:31 Xenial systemd[1]: Failed to start Docker Application Container Engine.
may 14 15:17:31 Xenial systemd[1]: docker.service: Unit entered failed state.
may 14 15:17:31 Xenial systemd[1]: docker.service: Failed with result 'exit-code'.

这里是sudo docker daemon -D

DEBU[0000] docker group found. gid: 999                 
DEBU[0000] Listener created for HTTP on unix (/var/run/docker.sock) 
INFO[0000] previous instance of containerd still alive (23050) 
DEBU[0000] containerd connection state change: CONNECTING 
DEBU[0000] Using default logging driver json-file       
DEBU[0000] Golang's threads limit set to 55980          
DEBU[0000] received past containerd event: &types.EventType:"live", Id:"", Status:0x0, Pid:"", Timestamp:0x57372cae 
DEBU[0000] containerd connection state change: READY    
DEBU[0000] devicemapper: driver version is 4.34.0       
DEBU[0000] devmapper: Generated prefix: docker-8:6-2101297 
DEBU[0000] devmapper: Checking for existence of the pool docker-8:6-2101297-pool 
DEBU[0000] devmapper: poolDataMajMin=7:0 poolMetaMajMin=7:1

DEBU[0000] devmapper: Major:Minor for device: /dev/loop0 is:7:0 
DEBU[0000] devmapper: Major:Minor for device: /dev/loop1 is:7:1 
DEBU[0000] devmapper: loadDeviceFilesOnStart()          
DEBU[0000] devmapper: Skipping file /var/lib/docker/devicemapper/metadata/transaction-metadata 
DEBU[0000] devmapper: loadDeviceFilesOnStart() END      
DEBU[0000] devmapper: constructDeviceIDMap()            
DEBU[0000] devmapper: constructDeviceIDMap() END        
DEBU[0000] devmapper: Rolling back open transaction: TransactionID=1 hash= device_id=1 
ERRO[0000] devmapper: Unable to delete device: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool 
WARN[0000] devmapper: Usage of loopback devices is strongly discouraged for production use. Please use `--storage-opt dm.thinpooldev` or use `man docker` to refer to dm.thinpooldev section. 
DEBU[0000] devmapper: Initializing base device-mapper thin volume 
DEBU[0000] devicemapper: CreateDevice(poolName=/dev/mapper/docker-8:6-2101297-pool, deviceID=1) 
DEBU[0000] devmapper: Error creating device: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool 
DEBU[0000] devmapper: Error device setupBaseImage: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool 
ERRO[0000] [graphdriver] prior storage driver "devicemapper" failed: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool 
DEBU[0000] Cleaning up old mountid : start.             
FATA[0000] Error starting daemon: error initializing graphdriver: devicemapper: Can't set task name /dev/mapper/docker-8:6-2101297-pool

这里是 ./check-config.sh 输出:

warning: /proc/config.gz does not exist, searching other paths for kernel config ...
info: reading kernel config from /boot/config-4.5.3-040503-generic ...

Generally Necessary:
- cgroup hierarchy: properly mounted [/sys/fs/cgroup]
- apparmor: enabled and tools installed
- CONFIG_NAMESPACES: enabled
- CONFIG_NET_NS: enabled
- CONFIG_PID_NS: enabled
- CONFIG_IPC_NS: enabled
- CONFIG_UTS_NS: enabled
- CONFIG_DEVPTS_MULTIPLE_INSTANCES: enabled
- CONFIG_CGROUPS: enabled
- CONFIG_CGROUP_CPUACCT: enabled
- CONFIG_CGROUP_DEVICE: enabled
- CONFIG_CGROUP_FREEZER: enabled
- CONFIG_CGROUP_SCHED: enabled
- CONFIG_CPUSETS: enabled
- CONFIG_MEMCG: enabled
- CONFIG_KEYS: enabled
- CONFIG_MACVLAN: enabled (as module)
- CONFIG_VETH: enabled (as module)
- CONFIG_BRIDGE: enabled (as module)
- CONFIG_BRIDGE_NETFILTER: enabled (as module)
- CONFIG_NF_NAT_IPV4: enabled (as module)
- CONFIG_IP_NF_FILTER: enabled (as module)
- CONFIG_IP_NF_TARGET_MASQUERADE: enabled (as module)
- CONFIG_NETFILTER_XT_MATCH_ADDRTYPE: enabled (as module)
- CONFIG_NETFILTER_XT_MATCH_CONNTRACK: enabled (as module)
- CONFIG_NF_NAT: enabled (as module)
- CONFIG_NF_NAT_NEEDED: enabled
- CONFIG_POSIX_MQUEUE: enabled

Optional Features:
- CONFIG_USER_NS: enabled
- CONFIG_SECCOMP: enabled
- CONFIG_CGROUP_PIDS: enabled
- CONFIG_MEMCG_KMEM: missing
- CONFIG_MEMCG_SWAP: enabled
- CONFIG_MEMCG_SWAP_ENABLED: missing
    (note that cgroup swap accounting is not enabled in your kernel config, you can enable it by setting boot option "swapaccount=1")
- CONFIG_BLK_CGROUP: enabled
- CONFIG_BLK_DEV_THROTTLING: enabled
- CONFIG_iosCHED_CFQ: enabled
- CONFIG_CFQ_GROUP_IOSCHED: enabled
- CONFIG_CGROUP_PERF: enabled
- CONFIG_CGROUP_HUGETLB: enabled
- CONFIG_NET_CLS_CGROUP: enabled (as module)
- CONFIG_CGROUP_NET_PRIO: enabled
- CONFIG_CFS_BANDWIDTH: enabled
- CONFIG_FAIR_GROUP_SCHED: enabled
- CONFIG_RT_GROUP_SCHED: missing
- CONFIG_EXT3_FS: missing
- CONFIG_EXT3_FS_XATTR: missing
- CONFIG_EXT3_FS_POSIX_ACL: missing
- CONFIG_EXT3_FS_SECURITY: missing
    (enable these ext3 configs if you are using ext3 as backing filesystem)
- CONFIG_EXT4_FS: enabled
- CONFIG_EXT4_FS_POSIX_ACL: enabled
- CONFIG_EXT4_FS_SECURITY: enabled
- Network Drivers:
  - "overlay":
    - CONFIG_VXLAN: enabled (as module)
- Storage Drivers:
  - "aufs":
    - CONFIG_AUFS_FS: missing
  - "btrfs":
    - CONFIG_BTRFS_FS: enabled (as module)
  - "devicemapper":
    - CONFIG_BLK_DEV_DM: enabled
    - CONFIG_DM_THIN_PROVISIONING: enabled (as module)
  - "overlay":
    - CONFIG_OVERLAY_FS: enabled (as module)
  - "zfs":
    - /dev/zfs: missing
    - zfs command: missing
    - zpool command: missing

如果有人可以帮助我,我将非常感激

【问题讨论】:

你重启系统了吗? 是的,我已经解决了问题,如下所述 【参考方案1】:

更新

似乎在较新版本的 docker 和 Ubuntu 中,docker 的单元文件只是被屏蔽了(指向 /dev/null)。 您可以通过在终端中运行以下命令来验证它:

sudo file /lib/systemd/system/docker.service
sudo file /lib/systemd/system/docker.socket

您应该看到单元文件符号链接到 /dev/null。 在这种情况下,您只需按照 S34N 的建议运行:

sudo systemctl unmask docker.service
sudo systemctl unmask docker.socket
sudo systemctl start docker.service
sudo systemctl status docker

我也会保留原来的帖子,它回答了错误日志,指出应该更换存储驱动程序:

原帖

我遇到了同样的问题,我尝试按照 Salva Cort 的建议修复它,但打印 /etc/default/docker 说:

#此文件不适用于 SYSTEMD

所以这是一个永久修复 that works for systemd(Ubuntu 15.04 及更高版本):

    创建一个新文件/etc/systemd/system/docker.service.d/overlay.conf,内容如下:

    [Service]
    ExecStart=
    ExecStart=/usr/bin/docker daemon -H fd:// -s overlay
    

    通过执行刷新更改:

    sudo systemctl daemon-reload
    

    验证配置是否已加载:

    systemctl show --property=ExecStart docker
    

    重启泊坞窗:

    sudo systemctl restart docker
    

【讨论】:

如果您将所有 docker 更改为 nvidia-docker,也适用于 nvidia-docker 我必须从/etc/systemd/system/docker.service 中的相应行添加整个命令行才能使其正常工作。给出的第 1 步只是覆盖了所有命令行参数,在我的情况下丢失了很多参数。 这个答案(不是链接的答案)似乎不再起作用,至少在 Ubuntu 16.04、Docker 版本 17.12.1-ce 上。出现阻止服务启动的错误,其中包含消息“ExecStart=/usr/bin/docker daemon -H fd:// -s overlay (code=exited, status=125)”和“unknown shorthand flag: 's ' in -s" 所以显然不再支持 -s 标志。 如果您只是在/etc/docker/daemon.json 编辑/创建一个文件并添加行 "storage-driver": "overlay2" 然后sudo systemctl restart docker.service,它甚至可以工作。跨度> 这些 systemctl 命令正是我今天早上升级到 20.04 后所需要的【参考方案2】:

以下取消屏蔽命令对我有用(Ubuntu 18)。希望它可以帮助那里的人...... :-)

sudo systemctl unmask docker.service
sudo systemctl unmask docker.socket
sudo systemctl start docker.service

【讨论】:

在 /etc/docker/daemon.json 中为“userns-remap”指定了错误的用户后,这为我解决了这个问题 “docker.service 的作业失败,因为控制进程以错误代码退出。”【参考方案3】:

通过 docker-machine 将 docker 从 17.05-ce 升级到 17.06-ce 后,我遇到了同样的问题

    更新 /etc/systemd/system/docker.service.d/10-machine.conf

    替换

    `docker daemon` => `dockerd`
    

    示例来自

    [Service]
    ExecStart=
    ExecStart=/usr/bin/docker deamon -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver aufs --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic
    Environment=
    

    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver aufs --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic
    Environment=
    

    通过执行刷新更改:

    sudo systemctl daemon-reload
    

    重启泊坞窗:

    sudo systemctl restart docker
    

【讨论】:

当我尝试针对新配置的 digitalocean 液滴运行 docker-machine 时,此解决方案对我有用。【参考方案4】:

好吧,我终于修好了

你所要做的就是加载一个不同的 storage-driver 在我的例子中,我将使用 overlay

    禁用 Docker 服务sudo systemctl stop docker.service 启动 Docker 守护进程overlay 驱动程序):sudo docker daemon -s overlay 运行演示容器sudo docker run hello-world

为了使这些更改永久生效,您必须编辑 /etc/default/docker 文件并添加选项:

DOCKER_OPTS="-s overlay"

下次Docker服务被加载,它会运行docker daemon -s overlay

【讨论】:

抱歉,编辑 /etc/default/docker 在 Ubuntu 上不起作用。它仍然像原来的问题一样卡住。但是,“sudo docker daemon -s overlay”始终有效。我每次都会使用这个命令。谢谢。 我无法使用第 2 步启动 docker。命令提示 -s 不是标志,daemon 不是 docker 命令。我正在使用 Docker 版本 18.09.0【参考方案5】:

按照此博客中的说明,我已经能够在内核升级后使其正常工作。

https://mymemorysucks.wordpress.com/2016/03/31/docker-graphdriver-and-aufs-failed-driver-not-supported-error-after-ubuntu-upgrade/

sudo apt-get update
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

sudo modprobe aufs

sudo service docker restart

【讨论】:

【参考方案6】:

查看其他一些答案后,问题似乎是服务未使用-s overlay 选项运行。

我还碰巧注意到 docker 在通话结束时尝试使用$DOCKER_OPTS 启动。

我能够export DOCKER_OPTS="-s overlay"(默认情况下 DOCKER_OPTS 为空)并让 docker 运行。

【讨论】:

【参考方案7】:

我在 Ubuntu 18.04.3 LTS 上安装新的 Docker(版本 19.03.3-rc1)时遇到了类似的问题。默认情况下,/etc/docker/daemon.json 文件在新安装中不存在。按照教程,我通过创建一个新的 daemon.json 文件将存储驱动程序更改为 devicemapper。它起作用了,但后来我删除了 daemon.json 文件,认为它会恢复为默认值,但它不起作用并且服务无法启动。

使用默认存储驱动程序再次创建 /etc/docker/daemon.json 文件已为我修复。


    "storage-driver": "overlay2"

【讨论】:

我在 docker 版本 19.03.12 上有类似的问题,我无法启动 docker 服务的原因是我在其他主题上的一个空的“/etc/docker/daemon.json”文件。删除此文件解决了我的问题。【参考方案8】:

sudo dockerd --debug 将有助于解决实际的痛点我在 ubuntu 20 LTS 上使用它修复了相同的错误

【讨论】:

【参考方案9】:

就我而言,我遇到了这个错误。

Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

我终于找到了,/etc/docker/daemon.json 错误,因为我添加了registry-mirrors


    "runtimes": 

        "nvidia": 
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
        
        

    # I forget to add a comma , here !!!!!!!
    "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]

我添加后,然后systemctl restart docker,我解决了。

【讨论】:

【参考方案10】:

就我而言,我从journalctl -xe command 收到以下错误

unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid character 'â' looking for beginning of object key string

只需用

清理 /etc/docker/daemon.json


【讨论】:

【参考方案11】:

我今天在升级到 ubuntu 内核并尝试了上面的许多解决方案后遇到了这个问题。然而,唯一有效的(Ubuntu 16.04.6 LTS)是删除(或重命名)文件夹:/var/lib/docker

请注意,这删除您所有的 docker 镜像、容器和卷等。所以在应用或备份之前了解其含义!

这里有更多细节: https://github.com/docker/for-linux/issues/162

【讨论】:

以上是关于无法在 Ubuntu 16.04 中启动 Docker 服务的主要内容,如果未能解决你的问题,请参考以下文章

无法在 Ubuntu (16.04) 上以伪模式启动 Hadoop (3.1.0)

window10和ubuntu16.04双系统装好后无法打开win10解决办法

重启ubuntu 16.04机器后无法启动Cassandra 3.11.6服务

Tomcat8无法在Windows Host上的VirtualBox Vagrant中以Ubuntu 16.04启动

无法在 Ubuntu 16.04 AWS EC2 实例上使用 puppeteer 启动 chromium headless

不漂亮怎么开发!Ubuntu 16.04 LTS桌面美化