Docker - enable remote HTTP API with SystemD and "daemon.json"

Denial of responsibility:

On an old Ubuntu 14.04 machine with Upstart as init system, I enabled the HTTP API by pointing DOCKER_OPTS

to /etc/default/docker

. He works.

$ docker version
Client:
 Version:      1.11.2
 (...)

Server:
 Version:      1.11.2
 (...)

      


Problem:

This solution does not work on the latest Ubuntu 16.04 machine with SystemD.

As stated at the top of the last file installed /etc/default/docker

:

# Docker Upstart and SysVinit configuration file

#
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
#   Please see the documentation for "systemd drop-ins":
#   https://docs.docker.com/engine/articles/systemd/
#
(...)

      

How I checked this information on the Docker for SystemD documentation page I need to populate a file daemon.json

, but as referenced there are some self-explanatory properties, but others may not be sufficiently explained.

That being said, I'm looking for help to convert this:

DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -G myuser --debug"

for an object daemon.json

?


Notes

PS1: I know what daemon.json

the default has debug: true

.

PS2:group: "myuser"

Will probably work like this or with an array of strings.

PS3: My main problem is using SOCK and HTTP at the same time.


EDIT (8/08/2017) After reading the accepted answer, check @white_gecko's answer for more information on this.

+3


source to share


3 answers


With a lot of fragmented documentation, it was difficult to fix this issue.

My first solution was to create daemon.json

with

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

      

This error did not work docker[5586]: unable to configure the Docker daemon with file /etc/docker/daemon.json

after trying to restart the daemon with service docker restart

. Note. The error I was unable to copy is bigger.

But what this error meant was that at the beginning of the daemon it was a conflict with the flag and configurations on daemon.json

.

When I looked at it with the help service docker status

, it was a parent: ExecStart=/usr/bin/docker daemon -H fd://

.

Which is weird because it differs from the configurations on /etc/init.d/docker

, which I thought were service configurations. The weird part was that the file init.d

does not contain an argument reference daemon

either -H fd://

.

After some research and a lot of searching for system directories, I recognize this directory (via the discussion on this topic in docker github issue # 22339 ).

Decision



Edited ExecStart

from /lib/systemd/system/docker.service

with this new value: /usr/bin/docker daemon

And created /etc/docker/daemon.json

with

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

      

Finally, restart the service with service docker start

and now I get the green light on service docker status

.

Tested new configurations with

$ docker run hello-world

Hello from Docker!
(...)

      

and

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

      

I hope this helps someone with a similar problem like mine! :)

+5


source


I had the same problem, and in fact in my eyes the simplest solution, which shouldn't touch any existing files that the system update process manages, is to use the system drop-in: Just create a file /etc/systemd/system/docker.service

that overwrites a specific part of the service in /lib/systemd/system/docker.service

.

In this case, the content /etc/systemd/system/docker.service

will 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 can even create a directory docker.service.d

that contains multiple files to overwrite different settings.)

After adding the file you just ran:

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

      

+2


source


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 using systemd

), this means the flag is -H

always used at startup dockerd

. If you specify a host entry in daemon.json

, it causes a configuration conflict (as in the above post) and Docker won't start.

To work around this issue, create a new file /etc/systemd/system/docker.service.d/docker.conf

with the following content to remove the -H

default argument used when starting the daemon.

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

      

Note that the c line ExecStart=

is actually required, otherwise it will fail:

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

After creating the file, you should run:

sudo systemctl daemon-reload
sudo systemctl restart docker

      

0


source







All Articles