links: [[Docker MOC]] --- # Docker Volumes In `docker-compose.yml`, you can create volumes for persistent data. These volumes are stored under docker app and can be used by containers Example ```docker volumes: node_modules: build: postgres-db: ``` In this example when you run `docker-compose up` it creates 3 volumes *node_modules*, *build*, *postgres-db* Now In order to map these volumes to container, you add **volumes** to the container, for example. If you want to use `postgres-db` everytime for your postgres container, you can do something like this ```docker services: db: image: postgres:alpine volumes: - "postgres-db:/var/lib/postgresql/data" ``` Now every time, the postgres container mounts postgres-db, so the data will be persistent The reason is we are mapping source `postgres-db` to the *postgres container* destination where it is looking for data `/var/lib/postgresql/data` --- tags: #docker