I would like to define a general mount volume - along with all the options I would like to have it associated - that can be reused across multiple services. In fact, I'm developing a project which uses the same source for several microservices. That way, the volume will be simpler to manage and modify.
To start off, I used the old way which took advantage of volumes_from
:
shared: image: phusion/baseimage volumes: - ./code:/var/www/html nginx: build: docker/nginx ports: - "8080:80" links: - php volumes_from: - shared
This works, but I had to define a shared
service to make it work. As of the 3.0 version, volumes
can be used, so I would like to define a general volume and use it into my nginx
service, but I'm not finding the right syntax:
version: '3.3' volumes: vol_test: type: bind source: ./code target: /var/www/html volume: nocopy: true services: nginx: build: docker/nginx ports: - "8080:80" volumes: - vol_test
Update
I've found that defining a volume the way I want could not be possible, since the following definition:
volumes: data-volume: type: bind source: ./code target: /var/www/html volume: nocopy: true
will produce this output when calling docker-compose up
:
ERROR: The Compose file './docker-compose.yml' is invalid because: volumes.data-volume value Additional properties are not allowed ('volume', 'source', 'type', 'target' were unexpected)
I guess I still have to use the volumes_from
way then. Can anybody confirm that?