The named volumes can be shared across containers in the following way:
services:
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes:
- app-volume:location_in_the_container
php:
build: ./php/
expose:
- 9000
volumes:
- app-volume:location_in_the_container
volumes:
app-volume:
Here’s an example config that I use for better understanding. I’m exposing the static files generated from my web
container to a named volume called static-content
which is then read and served by the nginx
container:
services:
nginx:
container_name: nginx
build: ./nginx/
volumes:
- static-content:/usr/src/app
web:
container_name: web
env_file: .env
volumes:
- static-content:/usr/src/app/public
environment:
- NODE_ENV=production
command: npm run package
volumes:
static-content: