for-linux icon indicating copy to clipboard operation
for-linux copied to clipboard

Ubuntu SystemD service file not backwardly compatible.

Open richard-scott opened this issue 8 years ago • 8 comments

Backwards compatibility is broken as the /lib/systemd/system/docker.service file is missing the following line:

--- /lib/systemd/system/docker.service  2017-12-05 11:33:34.080065032 +0000
+++ docker.service      2017-12-05 11:33:13.724679221 +0000
@@ -6,11 +6,12 @@
 Requires=docker.socket

 [Service]
+EnvironmentFile=-/etc/default/docker
 Type=notify
 # the default is not to use systemd for cgroups because the delegate issues still
 # exists and systemd currently does not support the cgroup feature set required
 # for containers run by docker
-ExecStart=/usr/bin/dockerd -H fd://
+ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
 ExecReload=/bin/kill -s HUP $MAINPID
 LimitNOFILE=1048576
 # Having non-zero Limit*s causes performance problems due to accounting overhead

richard-scott avatar Jan 18 '18 09:01 richard-scott

Submitted a PR to remedy this: ~https://github.com/docker/docker-ce-packaging/pull/76~

seemethere avatar Jan 18 '18 19:01 seemethere

ping @thaJeztah

seemethere avatar Jan 19 '18 02:01 seemethere

Docker installs /etc/default/docker because it's used by upstart (and potentially sysvinit?). For systemd, TMK we have never had an EnvironmentFile, and indeed EnvironmentFile has a different format than the normal simple shell script that /etc/default/docker has had since forever.

The preferred method of configuring docker would be via config file in /etc/docker/daemon.json, which is not created by default simply because the defaults are hard-coded and there is no need to set them there (and possibly an oversight since it can be confusing that nothing is there...).

You can also make use of systemd drop-ins to add customizations to the systemd unit file. https://docs.docker.com/engine/admin/systemd/#custom-docker-daemon-options

Closing because this is intentional, but feel free to discuss! Thanks!

cpuguy83 avatar Jan 19 '18 17:01 cpuguy83

It would be handy to remove the "-H fd://" from the SystemD service file then, as when you specify hosts like that you can't use the /etc/docker/daemon.json file to configure them.

Maybe moving that into the /etc/docker/daemon.json would be an idea?

richard-scott avatar Jan 24 '18 10:01 richard-scott

The default docker.service file has this:

ExecStart=/usr/bin/dockerd -H fd://

and I have this in my /etc/docker/daemon.json:

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

Why doens't docker like it?? I though that was what I should do?

I get this error:

 unable to configure the Docker daemon with file /etc/docker/daemon.json: the follwing directives are specified both as a flag and in the configuration file: hosts: (from flag: [fd://], from file: [unix:///var/run/docker.sock tcp://192.168.1.2:2375])

richard-scott avatar Mar 22 '18 08:03 richard-scott

While we'll be looking at changes in that area, currently, daemon.json options are not allowed to override options that are set as a daemon flag (--foo).

The .deb versions of docker support socket-activation, which is a systemd feature, and allows you to automatically start docker when accessing its socket (which has to be specified in the unit-file to make this work; this is the -H fd:// option).

To override this, follow the instructions in https://docs.docker.com/engine/install/linux-postinstall/#configuring-remote-access-with-systemd-unit-file to add a systemd drop-in configuration file that overrides the default ExecStart;

If you don't use socket-activation, you can remove the option from the ExecStart;

  1. Create a directory for your overrides (if it doesn't exist yet)

     sudo mkdir -p /etc/systemd/system/docker.service.d
    
  2. Create a drop-in file (e.g. name it hosts.conf)

     cat > /etc/systemd/system/docker.service.d/hosts.conf <<'EOF'
     [Service]
     # first reset the current ExecStart
     ExecStart=
     ExecStart=/usr/bin/dockerd
     EOF
    
  3. Reload systemd

     sudo systemctl daemon-reload
    
  4. Update your daemon.json if needed

  5. Restart docker to make the new configuration active

    sudo systemctl restart docker.service

thaJeztah avatar Mar 22 '18 13:03 thaJeztah

@thaJeztah : I think that you've forgot to specify the "[Service]" section in our /etc/systemd/system/docker.service.d/hosts.conf file. I think your point 2's drop-in file should be created as :

cat > /etc/systemd/system/docker.service.d/hosts.conf <<'EOF'
[Service]
# first reset the current ExecStart
 ExecStart=
 ExecStart=/usr/bin/dockerd
 EOF

kremerol avatar May 17 '20 06:05 kremerol

@kremerol you are so right, great catch! Editing now

thaJeztah avatar May 17 '20 08:05 thaJeztah