Is it possible to "combine" naming volumes and defining the path between containers? (docker compose)
I got a docker compose file with multiple services which need to share volumes. At the same time I want to specify the path of these volumes for backup purposes and to control on which drive the data resides.
Currently I am using an .env file combined with the docker-compose file to solve this as follows.
File .env
:
VOLUME_SHARED=/home/docker_user/data_service
File docker-compose.yml
version: '3.8'
services:
service1:
image: service1
volumes:
- ${VOLUME_SHARED}:/data
service2:
image: service2
volumes:
- ${VOLUME_SHARED}:/data
I know there are named volumes, but I couldnt find a way to define their path. Is there a way to locate all the information within the docker-compose file?
So to make it clear, is something like the following possible?
File docker-compose.yml
version: '3.8'
services:
service1:
image: service1
volumes:
- shared_data:/data
service2:
image: service2
volumes:
- shared_data:/data
volumes:
shared_data=/home/docker_user/data_service