3

I want to let a docker container access data from a mounted USB external hard drive (ExFat). I mounted the hard drive to an existing and empty /tmp/driveTest folder.

Next, I mounted the tmp folder into the docker-container by entering - '/tmp:/mnt/fs' in my docker-compose.yml file. When the Docker container starts, it successfully reads the data from the hard drive. But when I unmount the drive, without restarting the Docker container, the docker container still sees the folder/file structure while it should not.

When I start the Docker container and mount the drive then, it does not see the folder/file structure at all while it should.

I have tried the options with the privileged: true flag, but that does not seem to have any effect. I also unsuccessfully tried a different mount option:

- type: bind
  source: /tmp
  target: /mnt/fs

If it is possible what I want to achieve, then how?

1 Answer 1

2

I have found the solution, after a lot of trial-error.

In the docker-compose.yml file, I have created a named volume like this:

volumes:
 usb-drive:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /home/user/usb-mount/

Then, for the container service settings:

    volumes:
      - usb-drive:/mnt/usb

This volume gets updated when you perform mount and umount actions to the /home/user/usb-mount/ folder.

EDIT: Just make sure you mount the USB-drive(s) after the volume has been created. The path of the mount point is different than /home/user/usb-mount/ after the volume has been created by docker-compose.

You must log in to answer this question.

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