Skip to content

Instantly share code, notes, and snippets.

@sbrants
Last active August 31, 2021 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sbrants/d35777ab59865dac6e20 to your computer and use it in GitHub Desktop.
Save sbrants/d35777ab59865dac6e20 to your computer and use it in GitHub Desktop.
Mounting shared drives before starting containers when booting the OS.

I had trouble running containers automatically after booting.

The data volumes are mapped to mounted shared drives and this works as expected when starting the comtainers manually with docker-compose up. I've setup the restart: always policy in my docker-compose.yml so containers would be started after I reboot the OS. This resulted in the container not seing the content of the shared drives. The issue is that the containers would start before the drives were mounted.

To fix the issue I added a dependency on the docker daemon service so it would start after the shares are mounted.

First, create a systemd drop-in directory for the docker service:

mkdir /etc/systemd/system/docker.service.d

Then create a file called /etc/systemd/system/docker.service.d/remote-fs.conf with the following content:

[Unit]
After=remote-fs.target

Read current dependencies:

sudo systemctl show docker --property After
> After=network.target systemd-journald.socket docker.socket system.slice basic.target

Flush changes:

sudo systemctl daemon-reload

Check that it worked:

sudo systemctl show docker --property After
> After=remote-fs.target network.target systemd-journald.socket docker.socket system.slice basic.target

I found how to do this from:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment