Skip to content

Commit

Permalink
Merge pull request ChristianLempa#165 from cschug/improve_compose_pos…
Browse files Browse the repository at this point in the history
…tgres

Improve Docker Compose file of PostgreSQL
  • Loading branch information
ChristianLempa authored Mar 26, 2024
2 parents 1594210 + 3d4f62f commit 72bed1c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions docker-compose/postgres/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secret.*
49 changes: 35 additions & 14 deletions docker-compose/postgres/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
---
# (Optional) when using custom network
# networks:
# yournetwork:
# external: true
volumes:
postgres-data:
services:
postgres:
# (Recommended) replace "latest" with specific version
image: postgres:latest
image: postgres:16.2
container_name: postgres
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
# (Optional) when creating a new database
# - POSTGRES_DB=${POSTGRES_DB}
- 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
# (Optional) when using custom network
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
- 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:
driver: local

0 comments on commit 72bed1c

Please sign in to comment.