Docker - Enable Remote HTTP API with SystemD and "daemon.json" Docker - Enable Remote HTTP API with SystemD and "daemon.json" docker docker

Docker - Enable Remote HTTP API with SystemD and "daemon.json"


With a lot of fragmented documentation it was difficult to solve this.

My first solution was to create the daemon.json with

{  "hosts": [    "unix:///var/run/docker.sock",    "tcp://127.0.0.1:2376"  ]}

This does not worked this error docker[5586]: unable to configure the Docker daemon with file /etc/docker/daemon.json after tried to restart the daemon with service docker restart.Note: There was more on the error that I failed to copy.

But what this error meant it at the start the daemon it a conflict with a flag and configurations on daemon.json.

When I looked into it with service docker status this it was the parent process: ExecStart=/usr/bin/docker daemon -H fd://.

What it was strange because is different with configurations on /etc/init.d/docker which I thought that were the service configurations.The strange part it was that the file on init.d does contain any reference to daemon argument neither -H fd://.

After some research and a lot of searches of the system directories, I find out these directory (with help on the discussion on this issue docker github issue #22339).

Solution

Edited the ExecStart from /lib/systemd/system/docker.service with this new value:/usr/bin/docker daemon

And created the /etc/docker/daemon.json with

{  "hosts": [    "fd://",    "tcp://127.0.0.1:2376"  ]}

Finally restarted the service with service docker start and now I get the "green light" on service docker status.

Tested the new configurations with:

$ docker run hello-worldHello from Docker!(...)

And,

$ curl http://127.0.0.1:2376/v1.23/info[JSON]

I hope that this will help someone with a similar problem as mine! :)


I had the same problem and actually in my eyes the easiest solution which should doesn't touch any existing files, which are managed by the system update process is, to use a systemd drop-in:Just create a file /etc/systemd/system/docker.service which overwrites the specific part of the service in /lib/systemd/system/docker.service.

In this case the content of /etc/systemd/system/docker.service would be:

[Service]ExecStart=/usr/bin/dockerd --tlsverify --tlscacert=/etc/docker/ca.pem --tlscert=/etc/docker/server-cert.pem --tlskey=/etc/docker/server-key.pem -H=tcp://127.0.0.1:2375 -H=fd://

(You could even create a directory docker.service.d which contains multiple files to overwrite different parameters.)

After adding the file you just run:

$ sudo systemctl daemon-reload$ sudo systemctl restart docker


The solution described at https://docs.docker.com/engine/admin/#troubleshoot-conflicts-between-the-daemonjson-and-startup-scripts works for me:

One notable example of a configuration conflict that is difficult to troubleshoot is when you want to specify a different daemon address from the default. Docker listens on a socket by default. On Debian and Ubuntu systems using systemd), this means that a -H flag is always used when starting dockerd. If you specify a hosts entry in the daemon.json, this causes a configuration conflict (as in the above message) and Docker fails to start.

To work around this problem, create a new file /etc/systemd/system/docker.service.d/docker.conf with the following contents, to remove the -H argument that is used when starting the daemon by default.

[Service]ExecStart=ExecStart=/usr/bin/dockerd

Note that the line with ExecStart= is actually required, otherwise it'll fail with the error:

docker.service: Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.

After creating the file you must run:

sudo systemctl daemon-reloadsudo systemctl restart docker