compose.yaml.j2 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. services:
  2. {{ service_name | default('postgres') }}:
  3. image: docker.io/library/postgres:17.6
  4. container_name: {{ container_name | default('postgres') }}
  5. environment:
  6. - POSTGRES_INITDB_ARGS={{ postgres_initdb_args | default('--data-checksums') }}
  7. {% if postgres_host_auth_method -%}
  8. - POSTGRES_HOST_AUTH_METHOD={{ postgres_host_auth_method }}
  9. {% endif %}
  10. - POSTGRES_USER={{ database_user | default('postgres') }}
  11. {% if postgres_secrets_enabled -%}
  12. - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
  13. {% else -%}
  14. - POSTGRES_PASSWORD={{ database_password | default('postgres') }}
  15. {% endif %}
  16. - POSTGRES_DB={{ database_name | default('postgres') }}
  17. - TZ={{ container_timezone | default('UTC') }}
  18. {% if ports_enabled %}
  19. ports:
  20. - "{{ database_port | default(5432) }}:5432"
  21. {% endif %}
  22. healthcheck:
  23. test: ["CMD-SHELL", "pg_isready -U {{ database_user | default('postgres') }}"]
  24. start_period: 30s
  25. interval: 10s
  26. timeout: 10s
  27. retries: 5
  28. {% if network_enabled %}
  29. networks:
  30. - {{ network_name | default('bridge') }}
  31. {% endif %}
  32. {% if postgres_secrets_enabled %}
  33. secrets:
  34. - postgres_password
  35. {% endif %}
  36. volumes:
  37. - postgres_data:/var/lib/postgresql/data
  38. restart: {{ restart_policy | default('unless-stopped') }}
  39. {% if postgres_secrets_enabled %}
  40. secrets:
  41. postgres_password:
  42. file: secret.postgres_password.txt
  43. {% endif %}
  44. volumes:
  45. postgres_data:
  46. driver: local
  47. {% if network_enabled %}
  48. networks:
  49. {{ network_name | default('bridge') }}:
  50. {% if network_external %}
  51. external: true
  52. {% endif %}
  53. {% endif %}