costela / docker-volume-hetzner

Docker Volume Plugin for accessing Hetzner Cloud Volumes
MIT License
108 stars 16 forks source link

Use with existing volume? #4

Closed slhck closed 4 years ago

slhck commented 4 years ago

Thanks for this plugin, I think it could come in very useful! :tada:

I have an existing volume, let's call it volume-nbg1-1-test, with the ID 1234567.

How would I go about using this volume and attaching it to a Docker container?

I tried a simple docker-compose.yml with:

version: "3.5"

volumes:
    volume-nbg1-1-test:
        driver: hetzner

But it returns:

Creating volume "docker-volume-test_volume-nbg1-1-test" with hetzner driver

So it's adding some prefix, and I assume it's not looking for existing volumes?

costela commented 4 years ago

Yes, exactly. In this case you can either configure the plugin to use volume as a prefix (assuming this is a standard you have been using for other volumes), or, if it's about the single volume, just rename it to match the driver's default prefix.

TBH I haven't used the plugin myself for a while, but it should reuse the existing volume if the name matches.

slhck commented 4 years ago

Okay, I'll try the prefix thing. Perhaps the README could mention the use of an existing volume – I can provide a PR if I can get it to work. (Unfortunately I can't yet, see #6)

slhck commented 4 years ago

The problem with the prefix is that it will always be separated from the chosen volume name by a hyphen. Also, when creating the Docker volume, Docker Compose will additionally prefix the volume with the project name.

For example, I have the project docker-volume-test with the YAML config:

version: "3.5"

services:
    test:
        image: alpine
        volumes:
            - analytics:/test
        command: "tail -f /dev/null"

volumes:
    analytics:
        driver: hetzner
        driver_opts:
            fstype: xfs
            size: 10 # in GB, default: 10

Then it will create the following Hetzner volume:

docker-docker-volume-test_analytics

I'll shortly provide a PR that clarifies the README w.r.t. that.