Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 284
Gas Avatar asked May 18 '17 15:05

Gas


2 Answers

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:

  • https://github.com/moby/moby/issues/22339
  • https://github.com/moby/moby/issues/21559
  • https://github.com/moby/moby/issues/25471
  • https://github.com/moby/moby/pull/27473

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 service docker restart
like image 143
Andy Shinn Avatar answered Nov 16 '22 21:11

Andy Shinn


For systemd, my preferred method is to deploy a simple override file (you may need to first create the directory):

$ cat /etc/systemd/system/docker.service.d/override.conf
# Disable flags to dockerd, all settings are done in /etc/docker/daemon.json
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd

This removes the -H ... default flag from dockerd along with any other options and lets you manage docker from the daemon.json file. This also allows docker to make changes to their startup scripts as long as they don't modify the ExecStart and you'll continue to receive those changes without maintaining your own copy of the docker.service.

After creating this file, run systemctl daemon-reload; systemctl restart docker.

like image 18
BMitch Avatar answered Nov 16 '22 20:11

BMitch