arthur.sw
arthur.sw

Reputation: 11619

How to specify volume host path in docker-compose?

I want to share a volume among multiple containers, and specify the path for this volume on the host.

I used the following settings:

version: '3'
services:
    service1:
        image: image1
        volumes:
            - volume1:/volume1
    service2:
        image: image2
        volumes:
            - volume1:/volume1
volumes:
  volume1:
    driver: local                 # meaning?
    driver_opts:
      o: bind                     # meaning?
      type: none                  # meaning?
      device: /volume1            # the path on the host 

But I am not sure of the driver: local, type: none and o: bind options.

I would like to have a regular volume (like without specifying any driver nor driver_opts), just being able to specify the path on the host.

Upvotes: 0

Views: 1463

Answers (1)

Neel Kamath
Neel Kamath

Reputation: 1266

You're looking for a bind mount. Specifying the volumes key means that you're creating a volume in the Docker machine for persistent storage. Despite the name, a volume is not necessarily related to volumes.

Use something like:

version: '3'
services:
  service1:
    image: image1
    volumes:
      - type: bind # Host and Docker machines have identical views to the same directory; changes propagate both ways
        source: . # Host machine directory to mount
        target: /app # Docker machine directory to be mapped to

Upvotes: 2

Related Questions