Volume mount follows symbolic links

Hello everyone,

I just stumbled upon a docker-compose behaviour that surprised my a little bit in the first moment. I’ll try to sketch it in short with a simplified example.

My host directory looks like this:

- backend/component1/src/config.py
- backend/component2/src/linked_config.py -> ../../component1/src/config.py

The linked_config.py is a symbolic link to the config.py of the first component.

In my docker-compose.yml I mount the following volumes (in the global section):

   - ./backend/component2:/usr/src/component2
   - ./backend/component1/src/config.py:/usr/src/component2/linked_config.py

When I run the container, component2 is available as /usr/src/component2 as expected. The symbolic link still resides there, and the second volume (the config.py file itself) is available as /usr/component1/src/config.py (instead of /usr/src/component2/linked_config.py). So the symbolic link works and everything seems good.

However, I actually expected the link to be replaced (and thus, the config.py being copied). But I also understand that following the link makes sense. Can you please tell me:

1. Is the described behaviour (following the link when mounting a volume) intentional (and maybe even documented)?
2. Is it safe to rely on this behaviour, or may it silently change with future releases?

I’m using docker-compose 1.24.1 with Docker 19.03.8 on Ubuntu Xenial (16.04).

Thank you in advance for your answers.

Best regards,

1 Like