I have a compose file:
version: "3"
services:
db:
image: postgres:12.5
ports:
- "15432:5432"
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
volumes:
- ./postgres-data:/var/lib/postgresql/data
backend:
image: backend
depends_on:
- db
restart: always
ports:
- "6969:8000"
volumes:
- ./app:/app
When I run docker-compose up to start the 2 containers, I notice that:
- Docker auto creates the directory postgres-data, and it transfers the content of /var/lib/postgresql/data from container to host directory postgres-data
- With the backend service, Docker also auto creates the directory ./app, but instead of transfer the content of the /app directory (from container) to the ./app directory in host, it did the opposite: it transfer the content from the ./app directory in host to the /app in container.
Both service uses bind mount, and as I understand: bind mount always transfer the content from the host directory to the container. But this does not happen in the case of the db service
So where did I understand wrong here ?
Thanks in advance