--- name: postgresql networks: postgresql_net: attachable: true internal: true external: false name: postgresql driver: bridge ipam: driver: default config: - subnet: 172.20.25.0/24 ip_range: 172.20.25.0/24 gateway: 172.20.25.1 driver_opts: com.docker.network.bridge.default_bridge: "false" com.docker.network.bridge.enable_icc: "true" com.docker.network.bridge.enable_ip_masquerade: "true" com.docker.network.bridge.host_binding_ipv4: "0.0.0.0" com.docker.network.bridge.name: "postgresql" com.docker.network.driver.mtu: "1500" labels: com.postgresql.network.description: "is an isolated bridge network." services: postgresql_db: deploy: resources: limits: pids: 2048 # Limits the number of processes and threads (fork bomb protection). restart: always logging: driver: "json-file" options: max-size: "1M" max-file: "2" stop_grace_period: 1m container_name: postgresql_db image: docker.io/postgres:19-trixie@sha256:4ea94de574c17f0372722806c949757050fbb1cd7648410fe45d6bba275cc00e pull_policy: if_not_present volumes: - /docker/postgresql/config/postgresql.conf:/etc/postgresql/postgresql.conf - /docker/postgresql/18/production/db:/var/lib/postgresql env_file: # Compose loads each file that exists and skips a missing one: # '.env' for the Docker Compose CLI, 'stack.env' for Portainer. - path: .env required: false - path: stack.env required: false environment: PUID: "1000" PGID: "1000" TZ: Europe/Amsterdam # Adjust the timezone to match your local timezone. You can find the full list of timezones here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. POSTGRES_PASSWORD: ${POSTGRES_SUPERUSER_PASSWORD} # Fill in the value in both the .env and stack.env files POSTGRES_USER: ${POSTGRES_SUPERUSER_NAME} # Fill in the value in both the .env and stack.env files command: ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"] hostname: postgresql_db networks: postgresql_net: ipv4_address: 172.20.25.2 ports: - target: 5432 # container port host_ip: 127.0.0.1 # The Host IP mapping, unspecified means all network interfaces (0.0.0.0) published: 5432 # publicly exposed port protocol: tcp # tcp or udp mode: ingress # host: For publishing a host port on each node security_opt: - no-new-privileges:true labels: com.postgresql.db.description: "is a PostgreSQL database." healthcheck: disable: false test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER}"] interval: 10s timeout: 5s retries: 3 start_period: 10s start_interval: 5s