I created a volume named testVol
using following command in docker:
docker volume create testVol
Then I tried running a container which uses the same volume.
Here is the docker-compose.yml
file:
version: "3"
services:
webapp:
image: 'redis:latest'
volumes:
- testVol:/app/myfolder
volumes:
testVol:
external: true
When I run docker compose up
command, I can see that volume testVol
is being attached to the container. But along with it, i can see another anonymous volume created which is also attached to the same container.
What is this anonymous volume and why is it attached to the container?
If you look at the redis
image's Dockerfile, it contains the line
VOLUME /data
This tells Docker that there always must be some sort of volume mounted on /data
. If the operator doesn't explicitly mount something else there, Docker will create an anonymous volume and mount it.
In your setup you're mounting a volume on to /app/myfolder
but nothing into /data
, so the extra anonymous volume you're seeing is the volume Docker creates as a result of this VOLUME
statement.