简体   繁体   English

无法在docker-compose中定义的服务之间共享卷

[英]Can not share volume between services defined in docker-compose

I'm running Docker for Mac Version 17.12.0-ce-mac55 我正在运行Docker for Mac版本17.12.0-ce-mac55

I have a docker-compose file that I'm converting from docker-compose version 3 to version 2 to work better with Openshift. 我有一个docker-compose文件,我正在将其从docker-compose版本3转换为版本2,以便与Openshift更好地协同工作。

---
version: '2'
services:
  fpm:
    build:
      context: .
      dockerfile: Dockerfile.openshift
      args:
        TIMEZONE: America/Chicago
        APACHE_DOCUMENT_ROOT: /usr/local/apache2/htdocs
    image: widget-fpm
    restart: always
    depends_on:
      - es
      - db
    environment:
    # taken from sample.env
      - TIMEZONE=${TIMEZONE}
      - APACHE_DOCUMENT_ROOT=/usr/local/apache2/htdocs
      - GET_HOSTS_FROM=dns
      - SYMFONY__DATABASE__HOST=db
      - SYMFONY__DATABASE__PORT=5432
      - SYMFONY__DATABASE__NAME=widget
      - SYMFONY__DATABASE__USER=widget
      - SYMFONY__DATABASE__PASSWORD=widget
      - SYMFONY__DATABASE__SCHEMA=widget
      - SYMFONY__DATABASE__DRIVER=pdo_pgsql
      - SYMFONY_ENV=prod
      - SYMFONY__ELASTICSEARCH__HOST=es:9200
      - SYMFONY__SECRET=dsakfhakjhsdfjkhajhjds
      - SYMFONY__LOCALE=en
      - SYMFONY__RBAC__HOST=rbac
      - SYMFONY__RBAC__PROTOCOL=http
      - SYMFONY__RBAC__CONNECT__PATH=v1/connect
      - SYMFONY__PROJECT_URL=http://localhost
      - SYMFONY__APP__NAME=widget
      - SYMFONY__CURRENT__API__VERSION=1
    volumes:
      # use docroot env to change this directory
      - src:/usr/local/apache2/htdocs
      - symfony-cache:/usr/local/apache2/htdocs/app/cache
      - symfony-log:/usr/local/apache2/htdocs/app/logs
    expose:
      - "9000"
    networks:
      - client-network
      - data-network
    labels:
      kompose.service.expose: "false"
  webserver:
    build: ./provisioning/webserver/apache
    image: widget_web
    restart: "no"
    ports:
      - "80"
      - "443"
    volumes_from:
      - fpm:ro
    depends_on:
      - fpm
    networks:
      - client-network
    labels:
      com.singlehop.description: "Widget Service Web Server"
      com.singlehop.development: "false"
      kompose.service.expose: "true"
      kompose.service.type: "nodeport"
  db:
    build: ./provisioning/database/postgres
    image: widget_postgres
    restart: always
    volumes:
      - data-volume:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: widget
      POSTGRES_PASSWORD: widget
    expose:
      - "5432"
    networks:
      - data-network
    labels:
      com.singlehop.description: "Widget Service Postgres Database Server"
      com.singlehop.development: "false"
      io.openshift.non-scalable: "true"
      kompose.service.expose: "false"
      kompose.volume.size: 100Mi
  es:
    image: elasticsearch:5.6
    restart: always
    environment:
      #- cluster.name=docker-cluster
      #- bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    command: ["-Ecluster.name=docker-cluster", "-Ebootstrap.memory_lock=true"]
    ulimits:
      memlock:
        soft: -1
        hard: -1
    labels:
      com.singlehop.description: "Generic Elasticsearch5 DB"
      com.singlehop.development: "false"
      kompose.service.expose: "false"
      kompose.volume.size: 100Mi
    volumes:
      - es-data:/usr/share/elasticsearch/data
    expose:
      - "9200-9300"
    networks:
      - data-network
  migration:
    # @todo can we use the exact same build/image I created above?
    image: singlehop/widget-fpm
    environment:
    # taken from sample.env
      - TIMEZONE=America/Chicago
      - APACHE_DOCUMENT_ROOT=/usr/local/apache2/htdocs
      - GET_HOSTS_FROM=dns
      - SYMFONY__DATABASE__HOST=db
      - SYMFONY__DATABASE__PORT=5432
      - SYMFONY__DATABASE__NAME=widget
      - SYMFONY__DATABASE__USER=widget
      - SYMFONY__DATABASE__PASSWORD=widget
      - SYMFONY__DATABASE__SCHEMA=widget
      - SYMFONY__DATABASE__DRIVER=pdo_pgsql
      - SYMFONY_ENV=prod
      - SYMFONY__ELASTICSEARCH__HOST=es:9200
      - SYMFONY__SECRET=dsakfhakjhsdfjkhajhjds
      - SYMFONY__LOCALE=en
      - SYMFONY__PROJECT_URL=http://localhost
      - SYMFONY__APP__NAME=widget
      - SYMFONY__CURRENT__API__VERSION=1
    entrypoint: ["/usr/local/bin/php","app/console","--no-interaction"]
    command: doctrine:migrations:migrate
    volumes:
      - src:/usr/local/apache2/htdocs
    depends_on:
      - db
    networks:
      - data-network
    labels:
      com.singlehop.description: "Widget Automated Symfony Migration"
      com.singlehop.development: "false"
volumes:
  src: {}
  data-volume: {}
  es-data: {}
  symfony-cache: {}
  symfony-log: {}
networks:
  client-network:
  data-network:

I'm using the fpm service to act like a data container and share PHP code to the webserver service. 我正在使用fpm服务充当数据容器,并向Web服务器服务共享PHP代码。 For some reason the named volume src is not being shared to the webserver service/container. 由于某种原因,命名卷src没有共享到Web服务器服务/容器。 I've tried both setting the volumes and using volumes_from . 我尝试设置和使用volume_from

I'm assuming this is possible and I feel like it would be bad practice to do another copy of the source code in the widget_web Dockerfile. 我以为这是可能的,我觉得在widget_web Dockerfile中复制源代码是不好的做法。

The depends_on in the fpm service is breaking the named volume src . fpm服务中的depends_on 破坏了命名卷src When I removed the depends_on declaration it worked like I assumed it would work. 当我删除depends_on声明时,它像我认为的那样工作。 I can't tell if this is a bug or working as designed. 我不知道这是错误还是按设计工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM