9

I would like to go the systemd override way to let dockerd to listen to port 2376. So I followed this instruction.

On the other hand, I would like to dig into systemd to know what's going on under the hood. So I tried to inspect the unit file of docker by this command: systemctl cat docker.service

According to the output of the command, two files are involved.

  1. /lib/systemd/system/docker.service
  2. /etc/systemd/system/docker.service.d/override.conf

I believe the first one is default unit file for docker and the second one is the I created.

My problem is: Both files include sentances - ExecStart= and twice in the second file like:

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

Is it necessary to assign empty to ExecStart= before setting meaningful value ExecStart=/usr/bin/dockerd -H fd:// ?

I have spilit this post into two questions and the other one here.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
krave
  • 1,629
  • 4
  • 17
  • 36
  • I think there are two questions here. I would suggest moving your question the `--containerd` option to a new question. – larsks Aug 17 '21 at 13:27
  • I have post another question about the `--containerd` option here: https://stackoverflow.com/q/68823645/3256839 – krave Aug 17 '21 at 20:29
  • Updated the title to be narrowly a systemd question, since this applies to _all_ systemd override files that change `ExecStart`, not just the Docker ones. – Charles Duffy Aug 17 '21 at 21:14
  • @CharlesDuffy You are right. Thanks. :) – krave Aug 18 '21 at 04:25

1 Answers1

17

When you add entries to an override file, they are by default appended to any existing entries. That is, if your service example.service has:

[Service]
EnvironmentFile=/etc/foo.env

And you create /etc/systemd/system/example.service.d/override.conf with:

[Service]
EnvironmentFile=/etc/bar.env

Then the effective configuration is:

[Service]
EnvironmentFile=/etc/foo.env
EnvironmentFile=/etc/bar.env

That's fine for many directives, but a service can have only one ExecStart (unless it's a Type-oneshot service), so if you try to create an override file like this:

[Service]
ExecStart=/new/command/line

That will fail with an error along the lines of:

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

By specifying an empty ExecStart, you are "clearing out" all previous entries. So if your example.service has:

[Service]
ExecStart=/bin/foo

And you create an override like:

[Service]
ExecStart=
ExecStart=/bin/bar

The effective configuration is:

[Service]
ExecStart=/bin/bar
larsks
  • 277,717
  • 41
  • 399
  • 399