Docker Community Forums

Share and learn in the Docker community.

Mount disk image from inside container?


(Andig) #1

I’d like to customize a raspbian image and automate that process via docker. it requires mounting the image:

fdisk -l $IMAGE
mount -v -o offset=4194304 -t vfat --source $IMAGE --target /mnt/image/boot

This fails with:

mount: /mnt/image/boot: mount failed: Unknown error -1

even with --cap-add=SYS_ADMIN added when running the container (container is debian).

Is it possible to use mount inside a container?


(Vallard Benincosa) #2

For vfat file systems just use mcopy. Then you can add without mounting. But that’s if you want to do file copies into one. For linux I’ve used the fuseext2 to mount in user space and that works.


(David Maze) #3

To a first approximation, no; the usual practice is to mount any raw images or disks on the host system and then push them in with docker run -v options. Like the network, the filesystem setup is something that the Docker runtime takes care of and the process never thinks about.

It sounds like this task might not be a good one for Docker, and a VM or host-native process might be better.


(Vallard Benincosa) #4

The only way to get into those images is to mount the image in user space. xorriso also is good for getting info out of iso images. But I’ve had to use mcopy for vfat, fuseext2 for ext2 filesystems, and xorriso to extract ISO images. Mostly because my application is supposed to do this. I’ve had to work around not being able to mount images. But those have worked good enough for us. mcopy in particular is really small so makes the container not as big.