Sunday, November 13, 2022

docker-compose volume mount syntax

Using the host : guest format you can do any of the following:


volumes:

  # Just specify a path and let the Engine create a volume

  - /var/lib/mysql


  # Specify an absolute path mapping

  - /opt/data:/var/lib/mysql


  # Path on the host, relative to the Compose file

  - ./cache:/tmp/cache


  # User-relative path

  - ~/configs:/etc/configs/:ro


  # Named volume

  - datavolume:/var/lib/mysql



Long Syntax


As of docker-compose v3.2 you can use long syntax which allows the configuration of additional fields that can be expressed in the short form such as mount type (volume, bind or tmpfs) and read_only.


version: "3.2"

services:

  web:

    image: nginx:alpine

    ports:

      - "80:80"

    volumes:

      - type: volume

        source: mydata

        target: /data

        volume:

          nocopy: true

      - type: bind

        source: ./static

        target: /opt/app/static


networks:

  webnet:


volumes:

  mydata:




references:

https://stackoverflow.com/questions/40905761/how-do-i-mount-a-host-directory-as-a-volume-in-docker-compose

No comments:

Post a Comment