Postgres Setup with Docker Compose
Postgres Setup¶
Include a docker-compose.yml. Based on initial seed or postgres data, uncomment and use it.
version: '3.8'
services:
postgres:
container_name: ${POSTGRES_CONTAINER_NAME}
image: postgres:12
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres-data:/var/lib/postgresql/data
# - ./init-data.sql:/docker-entrypoint-initdb.d/init-data.sql
ports:
- "${POSTGRES_PORT}:5432"
volumes:
postgres-data:
Include a .env file with following variables.
POSTGRES_DB=db
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_HOST=localhost
POSTGRES_CONTAINER_NAME=postgres
POSTGRES_PORT=5432
Include a init-data.sql for seeding data if needed.
Run docker-compose up -d to start the container.