How to mount NFS share before starting docker service ?

Solution In Progress - Updated -

Environment

  • Red Hat Enterprise Linux 7
  • docker

Resolution

  • There may be situations where the docker containers may be in need of NFS shares to be mounted even before the containers are started
  • nfs mount can be specified as a prerequisite for docker service to start. This can be done by editing the service file for docker
  • Run the command # systemctl list-units -t mount | grep <mount-point>. This will fetch an output with the unit name. Consider a sample example like below,
# systemctl list-units -t mount | grep /run/user/6656
run-user-6656.mount      loaded     active      mounted      /run/user/6656
  • In this case /run/user/6656 is the mount point and run-user-6656.mount is the unit name. This unit name needs to be specified as a prerequisite in the docker service file
  • Open the docker service file and edit the lines as below,
[Unit]
Requires=<unit-name>
After=<unit-name>

Reload the daemon by running # systemctl daemon-reload. Try rebooting the host now and the nfs should be mounted before docker service is started.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments