With the below docker-compose.yml
file:
test:
build: ../../
dockerfile: docker/dev/Dockerfile
volumes_from:
- cachev
cachev:
build: ../../
dockerfile: docker/dev/Dockerfile
volumes:
- /build
entrypoint: "true"
cachev
service in above file launches volume container that creates anonymous volume in /var/lib/docker/
folder in docker host and creates mount point /cache
within volume container(xx_cachev
).
Does volumes_from
instruction under test
service create /build
mount point in xx_test
container? that points to /build
mount point of xx_cachev
container?
From
volumes_from
docs:So the short answer is yes:
volumes_from
mounts/build
volume defined bycachev
service insidetest
service.Long answer:
To answer your question let's run the
test
service:docker compose up test
Before answering your question, let's make sure the description is clear:
It's just regular container which exits immediately because of
entrypoint: "true"
.docker ps -a
should show:ac68a33abe59 cache "true" 16 hours ago Exited (0) 4 minutes ago cache_1
But before it exits it creates volumes specified in
volumes:
. So we can call it volume container if its volumes are used by other service, for caching for instance.Agree.
- /build
is anonymous volume. Can be verified by viewing all container mounts:docker inspect [cachev_container_id] --format '{{json .Mounts}}' | jq
should show something like:
jq
is great utility for working with jsons in bash. Install it for the above command to work.Don't see any evidence of mounts in
cachev:
service spec you provided.If you add mapping
- /tmp/cache:/cache
to itsvolumes
section and rundocker compose up test
again and inspect the exited container you should see:Please, note that
docker inspect [cachev_service_id] --format '{{json .Mounts}}' | jq
will show all container mounts including those specified indocker/dev/Dockerfile
usingVOLUME
instruction.To answer to your question we need to inspect
test
service container:docker inspect [test_container_id] --format '{{json .Mounts}}' | jq
:would show all the volumes specified in
docker/dev/Dockerfile
if any and all the volumes ofcachev
thanks tovolumes_from
instruction.You can see that both
test
andcache
containers have:in their mounts and this volume survives subsequent runs of
docker compose up test
Yes, you can verify by executing a command inside both containers. if creat file in test container under
touch /build/fromtest.txt
path, it will be visible in cacheV container on the same path/build/fromtest.txt
.volumes_from
compose-file-volumes_from
A demo you can try
log will be