Problem with -v mounted volume now empty

I used to be able to run a docker command line with the -v $PWD/host_dir:/etc/software and I would be able to see anything that was in the container image in /etc/software on my mac in $PWD/host_dir. Now when I mount a volume like that it is completely empty. I have turned off everything experimental and uninstalled Docker Desktop on my mac and re-installed it. I have disabled “Use gRPC FUSE for file sharing” to see if that was the problem. No matter what I do I can’t see the file(s) that should be in the /etc/software folder. This is important as one of the files is needed is for proper registration. If that file doesn’t exist it does a different registration process. I have been testing this over the last couple of years and suddenly it stopped. I did turn on “Enable VirtioFS accelerated directory sharing” at one point. This also meant I had the “Use the new Virtualization framework” enabled at the same time.

Any help would be greatly appreciated.

That’s not how it works. The container folder is used as a mount point for the host folder. The original content of a mount point will be eclipsed with the bind mounted host folder. I am not sure if Docker Desktop for Mac supports to map single files from the host to single files in the container, if it does, you could create a volume mapping per file. It would look smth like this -v $PWD/host_dir/file_1:/etc/software/file_1 -v $PWD/host_dir/file_2:/etc/software/file_2. As a result only the content of single files would be eclipsed (regardless whether the file existed in the container or not) instead of a whole folder.

There is also the possibility to use named volumes, which provide a feature that copies existing data from the container back to an empty named volume. To use a named volume, instead of using a host path, you need to use a name, smth like -v my_volume:/etc/software (replace my_volume with whatever you like, as long as it only consists of letters, dash and underscore). Then you could leverage docker cp to copy files from the host into the container.

If it’s your own image, you should think about creating a dedicated folder for the files and modify your image to use a modified configuration for your application to read the files from the new location.