services: {{ service_name }}: image: docker.io/library/postgres:17.6 {% if not swarm_enabled %} restart: {{ restart_policy }} container_name: {{ container_name }} {% endif %} hostname: {{ container_hostname }} environment: - POSTGRES_INITDB_ARGS={{ postgres_initdb_args }} {% if postgres_host_auth_method %} - POSTGRES_HOST_AUTH_METHOD={{ postgres_host_auth_method }} {% endif %} - POSTGRES_USER={{ database_user }} {% if postgres_secrets_enabled %} - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password {% else %} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} {% endif %} - POSTGRES_DB={{ database_name }} - TZ={{ container_timezone }} {% if network_mode == 'host' %} network_mode: host {% else %} networks: {% if network_mode == 'macvlan' %} {{ network_name }}: ipv4_address: {{ network_macvlan_ipv4_address }} {% elif network_mode == 'bridge' %} {{ network_name }}: {% endif %} {% endif %} {% if network_mode == 'bridge' %} ports: {% if swarm_enabled %} - target: 5432 published: {{ database_port }} protocol: tcp mode: host {% else %} - "{{ database_port }}:5432" {% endif %} {% endif %} volumes: - postgres_data:/var/lib/postgresql/data {% if postgres_secrets_enabled %} secrets: - postgres_password {% endif %} healthcheck: test: ["CMD-SHELL", "pg_isready -U {{ database_user }}"] start_period: 30s interval: 10s timeout: 10s retries: 5 {% if swarm_enabled %} deploy: replicas: 1 {% endif %} {% if postgres_secrets_enabled %} secrets: postgres_password: file: secret.postgres_password.txt {% endif %} volumes: postgres_data: driver: local networks: {% if network_mode == 'macvlan' %} {{ network_name }}: driver: macvlan driver_opts: parent: {{ network_macvlan_parent_interface }} ipam: config: - subnet: {{ network_macvlan_subnet }} gateway: {{ network_macvlan_gateway }} {% elif network_mode == 'bridge' %} {{ network_name }}: driver: {% if swarm_enabled %}overlay{% else %}bridge{% endif %} {% endif %}