Reputation: 727
I can create a docker volume using a relative path:
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: ${DB_PASS}
volumes:
- ./dbdata:/var/lib/postgresql/data
ports:
- '5432:5432'
Then, dbdata
will be available on my WSL 2
, and I will be able to enter it (with sudo su) and inspect its contents.
Yet, when I run docker volume ls
, I see only json below, which does not look like my dbdata volume at all:
[
{
"CreatedAt": "2020-11-03T09:19:37Z",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/5d668164c5bcdf4cc01e4c8fbc20cc1155f757d4ba06dc5118fa2d0a0b5efb9b/_data",
"Name": "5d668164c5bcdf4cc01e4c8fbc20cc1155f757d4ba06dc5118fa2d0a0b5efb9b",
"Options": null,
"Scope": "local"
}
]
But here I found this quote.
When you create a volume, it is stored within a directory on the Docker host
So my docker volumes should not be on my WSL 2 filesystem at all, they should reside on the Docker host instead. Then why do I see my volumes inside WSL?
Upvotes: 0
Views: 42
Reputation: 1360
Because, the quote you referenced applies to named volumes. That is, the volumes created either by docker volume create
command or volumes defined in docker-compose.yml in the root volumes
section, but not in volumes section inside a specific service.
More specifically, that syntax creates a bind mount and not a named volume.
Upvotes: 1