Docker Community Forums

Share and learn in the Docker community.

Cannot use mount within a Docker container

I’m trying to do the following within a Docker container:

docker run -it <image> bash
root$ dd if=/dev/zero of=file.fs bs=1024 count=1024
root$ mkfs.ext4 file.fs
root$ mkdir tmp
root$ mount -t ext4 file.fs tmp
mount: tmp/: mount failed: Unknown error -1
root$ dmesg
dmesg: read kernel buffer failed: Operation not permitted

The same commands above (with sudo) work fine on my host.

How can I get mount to succeed within the Docker container?
I’m trying to automate building some root filesystems for an embedded Linux target from a Docker container so I need to be able to mount from within.

Thanks in advance!

By default a container runs unprivleged. As such it lacks the required capabilities to perform a mount operation. Either you run your container privileged or figure out which capabilites are required and add just those, see:

2 Likes