Persistence of data in Docker
There are four possible options to mount any volume:
- Relative Path
- Absolute Path
- Docker Volume Default Path
- 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.