Search code examples
dockerdocker-volumemounted-volumes

will it possible to make docker mount with variable path or fix path is required?


Currently I am mounting https certificate for docker/container with below Windows machine path 'C:\Users\user.aspnet`.

volumes:
  - ~/.aspnet/https:/app/certs:ro

I want to change the location of and want to keep the https certificate (https) within the source code directory.

\\[Base_Path]\src\https

For user A, Base_Path = C:\Repos\app
For user B, Base_Path = C:\Code\application\app, etc.

Question is, will it be possible to mount the files which satisfy all the users? Or I need to fix a path for file mount (C:/https) ?


Solution

  • Compose volumes: can use relative paths. The path is interpreted relative to the location of the docker-compose.yml file. If you use multiple docker-compose -f options, the path is interpreted relative to the location of the first Compose file, even if this one is in a different directory.

    The setup you describe is quite common. IME it's actually a little unusual to use an absolute path as the host directory for a bind mount, exactly because different users will have different home directories but the layout of the source-controlled repository will be the same everywhere.