0

We have docker-ce running on some Ubuntu 16.04 LTS machines. The machines have a fast SSD for the OS, and a ZFS array for heavy data like docker containers.

Every time I'm brought in to fix the docker setup, it appears that an update reset the configuration to use the ZFS array for it's data.

That's probably because most guides are quite old. My changes, inspired by this article, are like so:

In /lib/systemd/system/docker.service, add -g "/mnt/var/lib/docker" like so:

ExecStart=/usr/bin/dockerd -g "/mnt/var/lib/docker" -H fd://

Also postpone the start of the service until the ZFS array is online:

[Unit]
After=network.target docker.socket firewalld.service zfs-mount.service

Even though this appears to be the recommended way to add a different directory according to the docs and old articles, this must be outdated because this file is reset on every update, and I have to manually change them back. After restarting the service, it works fine until the next update.

What is the proper way to make these changes stick while the package is updated?

1 Answer 1

1

This issue has do with systemd uses files.

As documented in man file-hierarchy, the /lib directory is for read-only vendor-supplied files, while /etc is for "system-specific configuration", which may override the default vendor-supplied files in /lib.

The correct place to place your modifications are in /etc/sytemd/system.

You can either completely replace the file in question with a file in /etc/ or you use a "drop-in" template to override only part of the file.

Search man systemd.unit for "Drop-in" for the details.

Files in /lib will continue to get overwritten during package upgrades, while changes to /etc/ will be preserved.

The advice about /lib vs /etc applies generally, not just to systemd.

systemd drop-in unit example

In /etc/systemd/system/docker.service.d/10-fix-execstart.conf:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -g "/mnt/var/lib/docker" -H fd://

So, you are following a pattern to create a file in a directory named after the service you want to override, declaring just the specific section and directive you want to override.

From man systemd.service:

If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect.

6
  • Thank you. I've accepted your answer. However, if you'd create an example for the drop-in or quote the documentation in your answer, as per stack exchange recommendations, that would be great for the next person that comes along from google.
    – Redsandro
    Mar 12, 2018 at 23:01
  • 1
    Updated with example. Mar 13, 2018 at 14:37
  • Had to do this on a different machine. Extra info: After adding the drop-in files, before updating, run systemctl daemon-reload
    – Redsandro
    Apr 10, 2018 at 12:16
  • I don't know how I did this before. I'm getting docker.service: Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing. -update- Solution here.
    – Redsandro
    May 26, 2018 at 9:15
  • 1
    @Redsandro, I updated my answer to reflect what's needed, which comes from the documentation for the ExecStart= directive in man systemd.service. Any time you having a problem with a systemd directive, use man systemd.directives to check the primary documentation for the directive first. May 29, 2018 at 16:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .