docker-compose.yml
version: '3'
services:
db:
image: postgres:10.0-alpine
env_file: .env
volumes:
- pg-data-volume:/var/lib/postgresql/data
ports:
- '${POSTGRES_HOST_PORT}:${POSTGRES_CONTAINER_PORT}'
networks:
- my-app-network
volumes:
pg-data-volume:
networks:
my-app-network:
.env
POSTGRES_HOST_PORT=5432
POSTGRES_CONTAINER_PORT=5432
POSTGRES_HOSTNAME=db
POSTGRES_USER=username
POSTGRES_PASSWORD=password
POSTGRES_DB=mydb
docker-compose up
to bring up services
docker-compose down
to bring down services
docker-compose down -v
to delete associated volumes. This deletes db data and initial credentials