Make shared volume

$ 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

Why?

Can you share in which documentation you found it like that? type=bind is not correct.

This will work:

docker volume create \
--driver local \
-o o=bind \
-o type=none \
-o device=/tmp/1hfhggggg \
test

--driver local is optional, as it’s the default driver anyway.

 
tmp.VTxgvtw3CT$ docker volume create     -o o=bind     -o type=none     -o device=/tmp/1hfhggggg     test
test
tmp.VTxgvtw3CT$ docker volume inspect test
[
    {
        "CreatedAt": "2024-07-18T10:04:31+02:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/test/_data",
        "Name": "test",
        "Options": {
            "device": "/tmp/1hfhggggg",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]
tmp.VTxgvtw3CT$ docker-compose build && docker-compose run --rm bash ls /tmp/1hfhggggg 
bash uses an image, skipping
Creating tmpvtxgvtw3ct_bash_run ... done
ls: /tmp/1hfhggggg: No such file or directory
ERROR: 1
tmp.VTxgvtw3CT$ 


To understand your last post we need context information: the content of the compose file.

My bad! I missed it, because I couldn’t make sense of it, as the volume mapping looks incomplete.

Please share a link to the docs that show that a volume can be used like that in a compose file.

I changed the volume directive line like this

- test:/tmp/1hfhggggg

Now it works!!!

Sorry, could you solve this problem too?