0

I have a part of a docker-compose file like that:

    volumes:
      - ../services/myApp:/code/services/myApp
      - /code/services/myApp/target

When I create the container, it creates the target folder on my host anyway.

The idea is that target folder would be excluded in the virtual mount. But it excludes all the files and folders inside of the target folder, but not the target folder itself. So when I create the container, the docker creates the empty target folder on my host. Which is not that bad, but it does create it with different permissions to what I have on my host for the myApp, which slightly inconvenient. Is there a way to make sure that target folder itself won't be created on my host when I do run the container ?

  • There is no Compose (or Linux) option to exclude a directory from a mount. You're mounting a host directory into the container, and then mounting a second anonymous volume over part of that; since the mount point is in the bind-mounted directory it must exist on the host as well. If this `volumes:` block is trying to overwrite the code in the image, a best practice might be to delete it entirely. – David Maze Jul 25 '23 at 23:57
  • Unfortunately I cannot rely on the target folder being copied over to the container or vice versa. The folder contains compilation binaries and these could differ on my own local machine depending on what OS I am running. I have to use volumes, and I have to exclude the target folder. It works almost perfectly. The only pain is that it creates the target folder with root permissions when the folder does not exist on host yet. It forces me to have that folder on my host prior to launching the container. I could not find a elegant way to solve that. – Jevgeni Merezin Jul 26 '23 at 02:28

0 Answers0