This project defines a local PostgreSQL database using Docker Compose. The manifest in docker-compose.yaml starts a single database container and exposes it on the configured host port.
- Docker Engine installed and running
- Docker Compose v2 (
docker compose) available in your shell
Create or review the .env file in this directory. The values below are already set for a local development database:
POSTGRES_USER=myuser
POSTGRES_PASSWORD=mypassword
POSTGRES_DB=mydatabase
POSTGRES_PORT=5432If you want to use a different database name, user, or port, update the values in .env before starting the container.
From this directory, run:
docker compose up -d dbThis creates and starts the PostgreSQL container in the background.
Check the container status:
docker compose psYou should see the db service as running.
To inspect the database logs:
docker compose logs -f dbThe database is exposed on your host machine at localhost:<POSTGRES_PORT>. With the default configuration, that is:
psql -h localhost -p 5432 -U myuser -d mydatabaseWhen prompted, enter the password from .env:
mypassword
To stop the container:
docker compose stop dbTo stop it and remove the container and its default network:
docker compose downTo remove the database volume as well (delete all local database data):
docker compose down -v- The Compose file maps the container's internal PostgreSQL port
5432to the host port configured byPOSTGRES_PORT. - The database data is stored in the Docker named volume
db_data, so it persists across container restarts unless you explicitly remove it withdocker compose down -v.