'Can I create a filesystem e.g. xfs in a Docker Container as part of an integration test?

I wish to test code that may have trouble on file systems that do not support d_type. In order to do so I would like to create two small xfs file systems that respectively have ftype=0 which does not support d_type, and ftype=1 which does.

I'd like to run these tests in a Docker container as that is how our testing is set up. It looks like I might be able to take advantage of the Docker devicemapper https://docs.docker.com/storage/storagedriver/device-mapper-driver/ .

I do not necessarily control the Docker Engine, that is I don't want to rely on creating these filesystems on the underlying machine and then exposing them to my container - so I would want to be able to do this in my Dockerfile or one I am running in the container.

But maybe there are other or better ways to do this.



Solution 1:[1]

I'm not sure this is a complete answer but hopefully a step towards it.

I am trying to do something similar. I want to do some tests using at least xfs, tmpfs & sshfs. I was hoping to find a fuse solution to emulate xfs as well.

You could definitely put a tmpfs, fuse-sshfs and even nfs inside a docker.

I have no experience with nbd but I think you could it within docker to provide xfs via a loopback device. See this blog for example.

This might not be necessary though as you can mount an image as a partition E.g.

mount -t <fs type> -o loop file.img /mnt

Assuming this works in docker we have our solution. I haven't tried this myself yet. If you get there first please post your solution (perhaps you did as this question is a year old).

See also Emulate a hard drive in Linux

Otherwise vagrant is probably good solution for this kind of problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bruce Adams