Skip to content

Instantly share code, notes, and snippets.

@shiny
Created January 16, 2025 12:09
Show Gist options
  • Save shiny/420086904158d42325a123a6b17a6d38 to your computer and use it in GitHub Desktop.
Save shiny/420086904158d42325a123a6b17a6d38 to your computer and use it in GitHub Desktop.
postgres docker-compose example
services:
db:
image: postgres:17.2
command:
- postgres
- -c
- config_file=/etc/postgresql/postgresql.conf
environment:
POSTGRES_USER: u301
POSTGRES_DB: u301
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
volumes:
- ./data:/var/lib/postgresql/data:Z
- ./wal-g:/bin/wal-g:ro
- ./my-postgres.conf:/etc/postgresql/postgresql.conf:ro
ports:
- 5432:5432
secrets:
- db_password
healthcheck:
#test: pg_isready -U postgres -h localhost
test: ["CMD-SHELL", "PGPASSWORD=$(cat /run/secrets/db_password) pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 5s
timeout: 5s
retries: 10
restart: unless-stopped
secrets:
db_password:
file: ./db_password.txt
@shiny
Copy link
Author

shiny commented Jan 16, 2025

  1. create db_password.txt and write a random strong password. you can use https://1password.com/password-generator
  2. run docker run -i --rm postgres cat /usr/share/postgresql/postgresql.conf.sample > my-postgres.conf to export a postgresql.conf.sample
  3. wal-g is powerful database backup tool, you can download it by wget https://github.com/wal-g/wal-g/releases/download/v3.0.5/wal-g-pg-ubuntu-24.04-amd64 -O wal-g.
    a. don't forget to run chmod +x ./wal-g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment