I am trying to make it possible to make and mount loop devices from within a container. This happens to work on my own development system, but is failing to work on our build server where it must be done for an automated build.
I am ensuring that I'm starting the container as privileged
. My container start line: docker run --privileged -it --rm <my_build_image>:latest /bin/bash
. From within the container I try the following steps from the losetup man page:
# dd if=/dev/zero of=/var/tmp/file.img bs=1024k count=4
...
# losetup --show --find /var/tmp/file.img
...
This should provide me the next unused loop device and have associated it to /dev/loopn. However, instead I'm presented with the following (and showing that the loop module is loaded and /dev/loop-control
is present):
[root@64a3a6900e0d /]# losetup --show --find /var/tmp/file.img
losetup: Could not find any loop device. Maybe this kernel does not know
about the loop device? (If so, recompile or `modprobe loop`.)
[root@64a3a6900e0d /]# ls /dev/loop*
/dev/loop-control
[root@64a3a6900e0d /]# lsmod | grep loop
loop 28072 0
On my own dev box, this works. I loaded loop
and started the container as privileged and was able to make loop devices. What should I check for now?
chroot
(the reason for loop devices). The build was put together by someone who isn't with the team now, and we didn't use Docker then. He made it work nicely, but much of the assumptions no longer apply. A good question.