I have a small Docker container from which I can access /dev/loop0. For this I've added to docker run
:
--device=/dev/loop-control:/dev/loop-control \
--device=/dev/loop0:/dev/loop0 \
On this loopback device I'm creating two or more partitions with parted/fdisk.
Now, I need to mount both partitions but unfortunately I cannot access either /dev/loop0p1
or /dev/loop0p2
or any other partition which was dynamically created.
Is there any way I could access them without having to spawn the container --privileged
?
Thank you.
Best Answer
Although the question is old this is still an issue.
The Linux kernel does not propagate device registration events to containers which is why
/dev/*
files do not appear within the container for devices that are added while the container is running.As a workaround within the container you can look for missing device files and create them like the following shell script does:
(I used
FILTER='^(r|n)bd'
to match/dev/rbdX
and/dev/nbdX
devices ceph creates dynamically in my case.)Please be aware that the script above does not unregister devices that have been removed on the host. In case you also need to do this you can run the following as well (
FILTER
needs to be specified):If your devices are created dynamically you may want to run both scripts periodically within the container.
You still need to run your container
--privileged
in order to work with devices.Also see this moby issue comment my script is based on.