Quantcast
Channel: Active questions tagged automount - Ask Ubuntu
Viewing all articles
Browse latest Browse all 225

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

$
0
0

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 bashroot@mycontainer# ls -al /some_folder/usb

Contents of mounted folder is empty inside container.


Viewing all articles
Browse latest Browse all 225

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>