简体   繁体   中英

How to select volume mountpoint in docker-compose.yml?

I need to mount volume /path/a from one container to /path/b in another container, but according to documentation only HOST:CONTAINER or HOST:CONTAINER:ro allowed to write in VOLUMES section.

Any ideas how to do that in docker-compose.yml?

You could create a volume on the host with a bind mount for both containers.

Example:

mkdir -p /mnt/shared-volume
docker run --name container1 -v /mnt/shared-volume:/path/a mycontainer
docker run --name container2 -v /mnt/shared-volume:/path/b mycontainer

Same with docker-compose.yml :

volumes:
 - /mnt/shared-volume:/path/a

And for the other container:

volumes:
 - /mnt/shared-volume:/path/b

Alternative solution:

Create a data volume container!

Example:

docker run --name datacontainer -v /mnt/shared-volume mycontainer /bin/true
docker run --name container1 --volumes-from datacontainer mycontainer
docker run --name container2 --volumes-from datacontainer mycontainer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM