This might be a duplicate, as i assume it's a common use case for docker-compose. However, i can't seem to find a similar question this specific scenario.
I have a docker-compose file with the following two services:
processService:
container_name: processservice
image: mcr.microsoft.com/dotnet/core/sdk:3.1
ports:
- 5001:80
volumes:
- ./backend/packages/dotnet:/backend/packages/dotnet
- ./backend/services/processService/src:/backend/services/processService/src
working_dir: /backend/services/processService/src/ProcessService.Application
command: dotnet watch run
organizationService:
container_name: organizationservice
image: mcr.microsoft.com/dotnet/core/sdk:3.1
ports:
- 5002:80
volumes:
- ./backend/packages/dotnet:/backend/packages/dotnet
- ./backend/services/organizationService/src:/backend/services/organizationService/src
working_dir: /backend/services/organizationService/src/OrganizationService.Application
command: dotnet watch run
As can be seen in the compose file, i use the same volume mount for both services, namely ./backend/packages/dotnet:/backend/packages/dotnet
.
I want to know whether or not it is possible to declare this volume once in the volumes section, and then reuse it across services.
I have tried searching for an answer to this. The answers i come across suggest to create a volume manually with docker volume create foo
and then using it as such:
...
volumes:
- foo:/backend/packages/dotnet
...
However, this doesn't make sense to me as I don't see how foo should be aware of the directory that I want it to read/write from when i havn't specified this at any point.
I have tried reading through the docker documentation, but I can't find anything related to creating a named volume mounting a specific directory.
Does anyone have any suggestions as to how to accomplish this?