Created
January 16, 2025 12:09
-
-
Save shiny/420086904158d42325a123a6b17a6d38 to your computer and use it in GitHub Desktop.
postgres docker-compose example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
db_password.txtand write a random strong password. you can use https://1password.com/password-generatordocker run -i --rm postgres cat /usr/share/postgresql/postgresql.conf.sample > my-postgres.confto export apostgresql.conf.samplewal-gis powerful database backup tool, you can download it bywget 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