Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Trying to mount/unmount USB drives so that their contents can be seen in a docker container while it is running

Writer Mia Lopez

I would like to mount and unmount USB drives such that their contents can be seen from within a Docker container while it is running. I've mapped the directory to the container which the USB drives will be mounted to.

The problem:

  • The docker container cannot see folders/files that are mounted to its volume mapped folder if the container was started before mounting the USB drives.
  • If the container is started after the USB is mounted the files can be seen, however, unmounting and mounting again will not show the contents.


Here's what I've tried:

I will be mounting a USB to the directory /some_folder/usb which is mapped to a docker container on Ubuntu 18.04 LTS w/ 4.15 kernel.

Start a container with the volume /some_folder mapped to the same named directory inside it:

$ docker run --name mycontainer -it -v /some_folder:/some_folder ubuntu bash

Detach from the container (CTRL+P+Q), connect a USB drive and mount it to the host directory as root:

$ mount /dev/sda1 /some_folder/usb/

Mount options:

$ mount | grep -i sda1
/dev/sda1 on /some_folder/usb type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

Verify there are files mounted to the host directory:

$ ls -al /some_folder/usb/
drwxr-xr-x 10 root root 8192 Jan 1 1970 .
drwxr-xr-x 3 root root 1024 Mar 13 16:44 ..
drwxr-xr-x 5 root root 8192 Jul 20 2018 files

Enter the container and check the mapped directory:

$ docker exec -it mycontainer bash
root@mycontainer# ls -al /some_folder/usb

Contents of mounted folder is empty inside container.

2

1 Answer

I know the question is old, but a solution would be using bind-mounts and setting the "bind propagation" to "shared".

Example:

docker run --name mycontainer -it --mount type=bind,source=/some_folder,target=/some_folder,bind-propagation=shared ubuntu bash

More info about bind-propagation:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy