When using Docker containers, if you need to use the mount command, you must start Docker in privileged mode
The way to start docker in privileged mode is to add --privileged for example docker run -it --privileged -d image name
If it is API mode, you need to add { "Privileged":true } in the HostConfig parameter
After starting docker in privileged mode, it may appear when entering into docker and using the mount command to mount some ISO or partition files
mount -o loop ./xxx.iso /mnt/cdrom
mount: ./xxx.iso: failed to setup loop device: No such file or directory
Of course, if you do not use privileged mode, using the mount command will prompt insufficient permissions
mount -t ./xxx.iso /dev/cdrom /mnt/cdrom
mount: permission denied
Let's assume we used privileged mode and encountered failed to setup loop device in case of mount
Then we need to pay attention to the following two points
1. Make sure the loop device kernel module is installed
lsmod |grep loop
If there is no output, you need to install a kernel module
modprobe loop
2. Confirm the size of the /dev and /dev/shm partitions
These two partitions usually mount tmpfs partition files. Such problems do not occur in normal physical servers or virtual servers, but are likely to occur in docker.
we need to use
df -h
Command to check the size of these two partitions
If the partition is too small , the problem of failed to setup loop device will also occur, and the author encountered this situation.
Adjustment method
mount -o size=10240M -o remount /dev
mount -o size=10240M -o remount /dev/shm
After I resize both partitions. get it