Merge pull request #165 from cschug/improve_compose_postgres

Improve Docker Compose file of PostgreSQL
This commit is contained in:
Christian Lempa 2024-03-26 12:04:04 +01:00 committed by GitHub
commit 72bed1c361
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 19 deletions

1
docker-compose/postgres/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
secret.*

View File

@ -1,24 +1,45 @@
---
# (Optional) when using custom network
services:
postgres:
image: postgres:16.2
container_name: postgres
environment:
- POSTGRES_INITDB_ARGS=${POSTGRES_INITDB_ARGS---data-checksums}
- POSTGRES_HOST_AUTH_METHOD=${POSTGRES_HOST_AUTH_METHOD-}
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
- POSTGRES_DB=${POSTGRES_DB:-$POSTGRES_USER}
- TZ=${TZ:-UTC}
ports:
- 5432:5432
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U "${POSTGRES_USER:-postgres}"']
start_period: 30s
interval: 10s
timeout: 10s
retries: 5
# (Optional) When using custom network, see also
# https://docs.docker.com/compose/compose-file/compose-file-v3/#networks
#
# networks:
# - yournetwork
secrets:
- postgres_password
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped
# (Optional) When using custom network, see also
# https://docs.docker.com/compose/compose-file/compose-file-v3/#network-configuration-reference
#
# networks:
# yournetwork:
# external: true
secrets:
postgres_password:
file: secret.postgres_password.txt
volumes:
postgres-data:
services:
postgres:
# (Recommended) replace "latest" with specific version
image: postgres:latest
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
# (Optional) when creating a new database
# - POSTGRES_DB=${POSTGRES_DB}
ports:
- 5432:5432
# (Optional) when using custom network
# networks:
# - yournetwork
volumes:
- postgres-data:/var/lib/postgresql/data
restart: unless-stopped
postgres_data:
driver: local