diff --git a/docker-compose/postgres/.gitignore b/docker-compose/postgres/.gitignore new file mode 100644 index 0000000..6e39f8f --- /dev/null +++ b/docker-compose/postgres/.gitignore @@ -0,0 +1 @@ +secret.* diff --git a/docker-compose/postgres/docker-compose.yaml b/docker-compose/postgres/docker-compose.yaml index 3a6d70e..811eb9e 100644 --- a/docker-compose/postgres/docker-compose.yaml +++ b/docker-compose/postgres/docker-compose.yaml @@ -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