docker-compose volumes_from equivalent with version 3

前端 未结 1 1090
生来不讨喜
生来不讨喜 2020-12-23 19:50

I\'m trying to create an Nginx/PHP FPM setup with docker compose and am having issues with the version 3 volumes syntax/changes.

My Dockerfile:

相关标签:
1条回答
  • 2020-12-23 20:13

    For using "Named volumes" for sharing files between containers you need to define

    1) volumes: section on the top level of yml file and define volume name

    volumes:
      php:
    

    2) define volume section on first container like you did (Where share will mount)

    web:
        volumes:
          - php:/var/www/html #<container_name>:<mount_point>
    

    3) define volume section on second container (Share will mount from)

    php:
      volumes:
        - php:/var/www/html
    

    4) (optionally) If you need to store volume data on the host machine you can use local-persist docker plugin. You can specify docker volume driver and path where you data will be stored.

    volumes:
      php:
        driver: local-persist
        driver_opts:
          mountpoint: /path/on/host/machine/
    

    In your case you forgot define volume name for php container. Just replace

      php:
        build: .
        volumes:
          - ./html:/var/www/html
    

    to

      php:
        build: .
        volumes:
          - php:/var/www/html
    

    and use Local Persist Docker Plugin

    0 讨论(0)
提交回复
热议问题