当前位置: 首页>>技术教程>>正文


无法在Ubuntu 16.04中启动Docker服务

, , , ,

问题描述

我一直在尝试在Ubuntu 16.04上使用Docker(1.10),但是安装失败,因为Docker Service无法启动。我已经尝试通过docker.io,docker-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.Event{Type:"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

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

最佳思路

更新资料

似乎在较新版本的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时说:

# THIS FILE DOES NOT APPLY TO SYSTEMD

因此,这是一个永久性修复程序that works for systemd(Ubuntu 15.04及更高版本):

  1. 创建具有以下内容的新文件/etc/systemd/system/docker.service.d/overlay.conf

    [Service]
    ExecStart=
    ExecStart=/usr/bin/docker daemon -H fd:// -s overlay
    
  2. 通过执行以下命令清除更改:

    sudo systemctl daemon-reload
    
  3. 验证配置是否已加载:

    systemctl show --property=ExecStart docker
    
  4. 重新启动docker:

    sudo systemctl restart docker
    

次佳思路

以下解掩命令对我有用(Ubuntu 18)。希望它可以帮助某人… 🙂

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

第三种思路

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

  1. 更新/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=
    
  2. 通过执行以下命令清除更改:

    sudo systemctl daemon-reload
    
  3. 重新启动docker:

    sudo systemctl restart docker
    

第四种思路

好吧,最后我修好了

您要做的就是在我的情况下加载其他storage-driver,我将使用overlay

  1. 禁用Docker服务:sudo systemctl stop docker.service

  2. 启动Docker Daemon(overlay驱动程序):sudo docker daemon -s overlay

  3. 运行演示容器:sudo docker run hello-world

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

DOCKER_OPTS="-s overlay"

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

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/7614.html,未经允许,请勿转载。