docker compose 共享卷并映射到路径

docker compose 共享卷并映射到路径

我有以下 yaml

version: '2'

services:
  database:
    image: sameersbn/mysql
    container_name: invoiceplane_mysql
    volumes:
      - /srv/docker/invoicePlane/mysql:/var/lib/mysql/
    environment:
      - DB_PASS=password
      - DB_USER=root
      - DB_NAME=invoiceplane
      - DB_REMOTE_ROOT_NAME=root
      - DB_REMOTE_ROOT_PASS=password
      - DB_REMOTE_ROOT_HOST=172.18.0.%
    ports:
      - "3306:3306"
    #entrypoint: [/bin/bash, /usr/bin/mysql]
    #entrypoint: mysql -h localhost -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.18.0.%' IDENTIFIED BY 'password'"
  invoiceplane:
    #image: coelis/invoiceplane
    build: ./invoiceplane
    entrypoint: ['/start.sh']
    ports :
      - "10180:80"
    volumes:
      - /srv/docker/invoicePlane/uploads:/var/www/html/uploads
    volumes_from:
      - invoiceplane-wipay
    depends_on:
      - database
      - invoiceplane-wipay
    links:
      - database:mysql
    environment:
      - MYSQL_PORT_3306_TCP_ADDR=172.18.0.2
      - MYSQL_ENV_MYSQL_ROOT_PASSWORD=password
  phpmyadmin:
     image: phpmyadmin/phpmyadmin
     ports :
       - "10181:80"
     environment:
       - MYSQL_USERNAME=root
       - MYSQL_PASSWORD=password
     links:
       - database:db
     depends_on:
       - database
  invoiceplane-wipay:
    build: ./php
    entrypoint: /bin/bash
    command: -c 'composer install && ./vendor/bin/watcher ./vendor/bin/phpunit ./tests ./src'
    volumes:
        - ~/Documents/Git/wipay_invoiceplane/invoiceplane-wipay:/usr/src/app:rw

我正在尝试将 invoiceplane-wipay 卷映射到应位于路径 /packages/invoiceplane-wipay 的 invoiceplane 卷

我尝试添加发票平面服务

volumes:
   - invoiceplane-wipay:/package/invoiceplane-wipay

我需要从invoiceplane-wipay服务到路径/包/invoiceplane-wipay发票飞机服务

答案1

从你的 yml 中:

  ...
  invoiceplane:
    volumes:
      - /srv/docker/invoicePlane/uploads:/var/www/html/uploads
    volumes_from:
      - invoiceplane-wipay
  ...
  invoiceplane-wipay:
    ...
    volumes:
        - ~/Documents/Git/wipay_invoiceplane/invoiceplane-wipay:/usr/src/app:rw

这会将 /usr/src/app 从 invoiceplane-wipay 容器挂载到具有相同路径的 invoiceplane 容器。如果要将其挂载到其他位置,则不能使用volumes-from,并且我不建议这样做,volumes-from因为它很快就会被弃用,而且在 swarm 模式下你不会找到对它的支持。您只需在 yml 的其他部分中包含相同的卷源:

  invoiceplane:
    volumes:
      - /srv/docker/invoicePlane/uploads:/var/www/html/uploads
      - ~/Documents/Git/wipay_invoiceplane/invoiceplane-wipay:/packages/invoiceplane-wipay

相关内容