Docker Compose Relative paths vs Docker volume

Persistence of data in Docker

There are four possible options to mount any volume:

  1. Relative Path
  2. Absolute Path
  3. Docker Volume Default Path
  4. Docker Volume with Absolute Path

Here is the example for above:

version: '3'
services:
    sample:
        image: sample
        volumes:
            - ./relative-path-volume:/var/data-two
            - /home/ubuntu/absolute-path-volume:/var/data-one
            - docker-volume-default-path-volume:/var/data-three
            - docker-volume-absolute-path-volume:/var/data-four
volumes:
  docker-volume-default-path-volume: {}
  docker-volume-absolute-path-volume:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: /home/path/of/your/folder

Relative Path: ./relative-path-volume:/var/data-two

Absolute Path: /home/ubuntu/absolute-path-volume:/var/data-one

Docker Volume Default Path: docker-volume-default-path-volume:/var/data-three

Docker Volume with Absolute Path: docker-volume-absolute-path-volume:/var/data-four

This works for any server as we customize the volume device property to the respective directory path.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)