$ cat docker-compose.yml
version: "3.8"
services:
bash:
image: bash
volumes:
- test
volumes:
test:
external
$ docker volume create -d local -o type=bind -o device=/tmp/1hfhggggg test
test
$ docker volume inspect test
[
{
"CreatedAt": "2024-07-17T11:01:31+02:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/test/_data",
"Name": "test",
"Options": {
"device": "/tmp/1hfhggggg",
"type": "bind"
},
"Scope": "local"
}
]
$ docker-compose build
bash uses an image, skipping
$ docker-compose run --rm bash ls /tmp/1hfhggggg
Creating tmphezrgbvjnk_bash_run ... done
ls: /tmp/1hfhggggg: No such file or directory
ERROR: 1
Why?
Alternatively
$ docker-compose run --rm bash ls /var/lib/docker/volumes/test/_data
Creating tmphezrgbvjnk_bash_run ... done
ls: /var/lib/docker/volumes/test/_data: No such file or directory
ERROR: 1