Learn a lit more about Linux services.

How to modify the Docker service initialization on Ubuntu

I had a problem with a disk mount in my Ubuntu. When it happens, my docker service starts with an error. The error is why my docker data is on this disk.

To fix this, I changed the docker service configuration to wait for a disk mount before starting. I learned the correct way to do this correctly.

First, you must understand that the fire responsible for initializing the docker service in Ubuntu is /lib/systemd/system/docker.service, and it's managed by Docker, so we must not change this.

To change the behavior of the service, we need to create a directory /etc/systemd/system/docker.service.d/ and inside, then create a file mount.conf:


This configuration will add or change the RequiresMountsFor configuration of the file /lib/systemd/system/docker.service using the value /mnt/disk1, which is the disk name I need to wait to be mounted before docker start.

After creating the file in /etc/systemd/system/docker.service.d/, you must reload the systemd daemon for the changes to take effect using the command:

sudo systemctl daemon-reload

After that, you can restart the docker service to apply the changes with the command:

sudo systemctl restart docker

Every time the docker service is initialized, it will verify if a disk has been mounted before.

March 08, 2023

Background image credits forGabriel Heinzer

Copyright © Gatsby-starter-grayscale 2019