Docker container gives different ls -f (readdir) results on different linux hosts

We are trying to use docker containers to make our software builds repeatable in baselined environment. One of the tools in the build toolchain (Wind River) is called mkromfs, it grabs files in certain folder, converts them to a filesystem that is then loadable to the rom on targert platform (which is an embedded device, but that is not important here). The issue is: that utility relies on filesystem order of files and gives different results when I run the container on Linux RHEL host and different results when I run it in Linux VM (Docker for Windows with Linux containers support enabled, I don’t know what Linux distro is inside…). Basically the same can be quickly reproduced by generating folder with files a and b, and then doing ls -f on the folder, different hosts give files in different order (although the results seem to be repeatable on that specific hosts).

The container we use is based on ubuntu latest, but same issue occurred if I try another base images, it seems to rely on host system, not the container (my guess is that it actually uses the host file system somehow, but I thought dockers use union FS).

Now of course I do not want to risk that someone will try to repeat the build on slightly different Linux host in the future and will come to a different result. I also understand that order of ls -f (or readdir() internally) is given by OS and filesystem. I also cannot change mkromfs utility since there is no source available to it.

My tries and ideas were so far:

  • Have a folder in container with predictable filesystem in it (at least the same one), so I wanted to mount something like ramfs or tmpfs, unfortunately this does not seem to be allowed in containers (gives permission denied)
  • Hack our romfs content to make it a single file so that ordering won’t matter (I don’t like this since it means modifying our final product because of the integration technology, this is a last resort for me…)
  • Switch to virtual machines for repeatability. (I absolutely want to avoid this, containers are much smaller and faster…)
  • Add requriements for the filesystem used for docker images, the RHEL machine we use has it on ext3 filesystem, I have not tried it yet and also I am not sure if this can help, plus I still don’t know what filesystem do Linux VM hosts in Windows Dockers use or how to figure that out…

Is there some way to save the docker container approach and have this process repeatable? Ideally there would be no difference in build run in container on remote Linux host as is on my Windows 10 machine running Docker with Linux support. I am new to the whole docker container technology and partially also to Linux, I must have missed something…

Source: StackOverflow