Docker - Can't share data between containers within a volume (docker-compose 3)

后端 未结 2 646
既然无缘
既然无缘 2021-02-07 20:15

I have some containers for a web app for now (nginx, gunicorn, postgres and node to build static files from source and a React server side rendering). In a Dockerfile for the no

2条回答
  •  星月不相逢
    2021-02-07 20:54

    Two changes you need. In your node service add the volume like:

    volumes:
      - vnode:/usr/src/bundle_client
    

    Since you want to share /usr/src/bundle_client you should NOT be using /usr/src/ because that will share the full folder and the structure too.

    And then in your nginx service add the volume like:

    volumes:
      - type: volume
        source: vnode
        target: /var/www/test/static
        volume:
          nocopy: true
    

    The nocopy: true keeps our intention clear that on initial map of the container the content of the mapped folder should not be copied. And by default the first container to get mapped to the volume will get the contents of the mapped folder. In your case you want this to be the node container.

    Also before testing make sure you run below command to kill the cached volumes:

    docker-compose down -v
    

    You can see during my test the container had the files:

提交回复
热议问题