Environment:DataExpert io Data engineer handbook PostgreSQL Docker Environment
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Data_Modeling |
| Last Updated | 2026-02-09 06:00 GMT |
Overview
Docker Compose environment with PostgreSQL 14 and PGAdmin 4 for dimensional data modeling exercises.
Description
This environment provides a containerized PostgreSQL 14 database pre-loaded with sample data via pg_restore, paired with a PGAdmin 4 web interface for SQL development. It is used for the Dimensional Data Modeling module of the Data Engineer Handbook bootcamp. The database is automatically seeded on first startup using an init script that restores a dump file and optionally runs SQL files from the homework directory.
Usage
Use this environment for any Dimensional Data Modeling workflow that requires a PostgreSQL database with pre-loaded sample data. It is the mandatory prerequisite for running the Pg_restore_Init_Script, SQL_Select_Query_Pattern, and Docker_Compose_PostgreSQL_Stack implementations.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux, macOS, or Windows with WSL2 | Docker Desktop required |
| Software | Docker Engine + Docker Compose | v2.x recommended |
| Software | DataGrip or any SQL editor | For running SQL queries |
| Disk | ~500MB | PostgreSQL data + PGAdmin data volumes |
| Network | Ports 5432 and 5050 available | PostgreSQL and PGAdmin respectively |
Dependencies
System Packages
- Docker Engine with Docker Compose v2
- PostgreSQL 14 (via `postgres:14` Docker image)
- PGAdmin 4 (via `dpage/pgadmin4` Docker image)
Container Images
- `postgres:14` — PostgreSQL database server
- `dpage/pgadmin4` — Web-based database administration tool
Credentials
The following environment variables must be set in `.env` (copy from `example.env`):
- `POSTGRES_SCHEMA`: Database schema name (default: `postgres`)
- `POSTGRES_USER`: PostgreSQL superuser name (default: `postgres`)
- `POSTGRES_DB`: Database name (default: `postgres`)
- `POSTGRES_PASSWORD`: PostgreSQL password (default: `postgres`)
- `HOST_PORT`: Host port mapping for PostgreSQL (default: `5432`)
- `DOCKER_CONTAINER`: Container name (default: `my-postgres-container`)
- `PGADMIN_EMAIL`: PGAdmin login email (default: `postgres@postgres.com`)
- `PGADMIN_PASSWORD`: PGAdmin login password (default: `postgres`)
- `PGADMIN_PORT`: Host port for PGAdmin web UI (default: `5050`)
Quick Install
# Copy environment configuration
cp example.env .env
# Start PostgreSQL and PGAdmin containers
docker compose up -d
# Verify containers are running
docker compose ps
Code Evidence
Docker Compose service definition from `docker-compose.yml:1-32`:
services:
postgres:
image: postgres:14
restart: on-failure
container_name: ${DOCKER_CONTAINER}
environment:
- POSTGRES_DB=${POSTGRES_SCHEMA}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- "${HOST_PORT}:5432"
volumes:
- ./:/bootcamp/
- ./data.dump:/docker-entrypoint-initdb.d/data.dump
- ./scripts/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh
- postgres-data:/var/lib/postgresql/data
Database initialization from `scripts/init-db.sh:1-29`:
#!/bin/bash
set -e
pg_restore \
-v \
--no-owner \
--no-privileges \
-U $POSTGRES_USER \
-d $POSTGRES_DB \
/docker-entrypoint-initdb.d/data.dump
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `WARNING: .env file does not exist!` | Missing environment file | Copy `example.env` to `.env`: `cp example.env .env` |
| `port is already allocated` on 5432 | Local PostgreSQL already using port 5432 | Change `HOST_PORT` in `.env` to another port (e.g., 5433) |
| `pg_restore: error: connection to server failed` | Container not fully started | Wait for container to initialize; check with `docker compose logs postgres` |
Compatibility Notes
- macOS: Docker Desktop for Mac required. Ensure sufficient memory allocated (at least 2GB).
- Windows: Requires WSL2 backend for Docker Desktop.
- Linux: Native Docker Engine works directly.
- Data Persistence: PostgreSQL data is stored in a named volume `postgres-data`. Use `docker compose stop` to preserve data; `docker compose down -v` removes volumes.