dockerserviceconfigurationubuntu-16.04

Unable to start docker after configuring hosts in daemon.json


I'm trying to configure docker (version 17.03.1-ce) in ubuntu 16.04 using configuration file /etc/docker/daemon.json to add an host:

{
  "debug": true,
  "hosts": ["tcp://0.0.0.0:1234", "unix:///var/run/docker.sock"],
  "dns"  : ["8.8.8.8","8.8.4.4"]
}

when I try to restart docker.. it fails

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

watching on systemctl status docker.service:

Starting Docker Application Container Engine...
docker-slave-ubuntu-build dockerd[24806]: unable to configure the Docker daemon with file /etc/docker/daemon.json: 
the following directives are specified both as a flag and in the configuration file: 
hosts: (from flag: [fd://], from file: [tcp://0.0.0.0:4243 unix:///var/run/docker.sock])

Where I can remove the mentioned flag ? I have to modify maintainer's script ?


Solution

  • It looks like this is an issue merging configuration from both the command line and configuration file. The default systemd unit file is specifying -H fd:// and it conflicts with your tcp://0.0.0.0:1234 and unix:///var/run/docker.sock.

    There are a number of GitHub issues on the subject:

    They don't seem to consider this a bug. But it is definitely an annoyance. A workaround is to copy the default unit file and remove the -H fd:// from it:

    $ sudo cp /lib/systemd/system/docker.service /etc/systemd/system/
    $ sudo sed -i 's/\ -H\ fd:\/\///g' /etc/systemd/system/docker.service
    $ sudo systemctl daemon-reload
    $ sudo systemctl restart docker