MatchbookLab / local-persist

Create named local volumes that persist in the location(s) you want
MIT License
852 stars 123 forks source link

docker-compose v3 example #81

Closed joepagan closed 3 years ago

joepagan commented 3 years ago

Hey,

I'm trying to share the same volume over multiple services and found a suggestion that in v3 we need to use this docker plugin.

I see from your readme we wont be able to install the plugin on macos, so, it will need to be setup as a container though I am unsure how to succesfully accomplish this can you clarify this for me?

The readme suggests a docker run command, though this seems like a lenghty step which will need to be customised & run for each app we want to work with, is there a way to just have the app-specific docker-compose handle that step too? Or will that not be possible as the docker-compose.yml will have no idea what loca-persist driver is at that point?

Example of what I want

version: "3.8"
services:
    php-fpm:
      build:
        context: ./
        dockerfile: ./docker/development/config/php-fpm.dockerfile
      networks:
        - app
      ports:
        - 9000:9000
      volumes:
        - php-fpm:/var/www/html
      env_file: .env.dev
    nginx:
      build:
        context: ./
        dockerfile: ./docker/development/config/nginx.dockerfile
      ports:
        - 80:80
      networks:
        - app
      volumes:
        - php-fpm:/var/www/html
    driver-persist:
      image: cwspear/docker-local-persist-volume-plugin
      volumes:
        - /run/docker/plugins/:/run/docker/plugins/
        - ./json:/var/lib/docker/plugin-data/ \
        - ./:/var/www/html
volumes:
  mysqldata:
  php-fpm:
    driver: local-persist
    driver_opts:
      mountpoint: ./
networks:
  app:
    driver: bridge

error when I try run:

Creating volume "docker3-test_php-fpm" with local-persist driver
ERROR: Volume php-fpm specifies nonexistent driver local-persist
CWSpear commented 3 years ago

Yeah, it's probably not possible, and for the reason you stated.

The idea of Docker plugins is that they're always running, and that they're global. In the case of getting it to work with macos, you can run it in the container, but you still need it to have just the once instance.

You can create a separate docker-compose.yml to make it easier to configure, and you could configure it to run when Docker does and/or on startup, etc, but that's beyond the scope of this project.

joepagan commented 3 years ago

Fair enough, thanks for getting back to me. Good to know that it's an option for v3 in that way.

For the sake of managing it all in app-specific files I think it makes sense to retreat back to a v2 docker-compose config using volumes_from.