Skip to main content

[Docker] volumes

Intro

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.

While bind mounts are dependent on the directory structure and OS of the host machine, volumes are completely managed by Docker.

docker-volumes

Use a volume with Docker Compose and Postgresql

services:
db:
image: postgis/postgis:11-3.3-alpine
volumes:
- myappDB:/var/lib/postgresql/data

volumes:
myappDB:

Running docker compose up for the first time creates a volume. The same volume is reused when you subsequently run the command.

Reference