Simple PostgreSQL docker-compose config

This is a simple docker-compose config for PostgreSQL.

In order to use it, first create a .env with the password:

echo "POSTGRES_PASSWORD=$(pwgen 30)" > .env

now create a docker-compose.yml file in the same directory with the following content:

services:
  postgres:
    image: postgres:16
    restart: unless-stopped
    volumes:
      - ./pg_data:/var/lib/postgresql/data
    ports:
      - 5432:5432
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=mydatabase
      - POSTGRES_USER=mydatabase

Now you can start the database with docker-compose up. By default, it will be available at localhost:5432 (the default port for Postgres).