[Unit] Description=PostgreSQL Database Server Documentation=https://hub.docker.com/_/postgres/ After=network.target postgresql-upgrade.service postgresql-init.service Requires=postgresql-upgrade.service postgresql-init.service Before=postgresql.target # Only start if PostgreSQL has been configured ConditionPathExists=/etc/quadlets/postgresql/config.env # and initialized ConditionPathExists=/var/lib/quadlets/postgresql/.initialized # and upgraded ConditionPathExists=/var/lib/quadlets/postgresql/latest/docker/PG_VERSION # Start/stop this unit when the target is started/stopped PartOf=postgresql.target [Container] ContainerName=postgresql-server Image=docker.io/library/postgres:${PG_MAJOR}-alpine # Network configuration Network=host # PostgreSQL storage is specific to major version Environment=PGDATA=/var/lib/postgresql/${PG_MAJOR}/docker # Safety flag to avoid initialization of an unwanted database Environment=DATABASE_ALREADY_EXISTS=true # Those environment variables will be injected by podman into the container EnvironmentFile=/etc/quadlets/postgresql/config.env # Volume mounts Volume=/var/lib/quadlets/postgresql:/var/lib/postgresql:z # Set PostgreSQL command line arguments Exec=${POSTGRES_ARGS} # No need for root privileges User=postgres Group=postgres # UID/GID mapping to map the postgres (70) user inside the container to arbitrary user 10004 / group 10000 on the host UIDMap=0:1000000:65535 UIDMap=+70:10004:1 GIDMap=0:1000000:65535 GIDMap=+70:10000:1 # Avoid issues with built-in volumes being created by root PodmanArgs=--image-volume=ignore # Health check HealthCmd=pg_isready -U $POSTGRES_USER -d $POSTGRES_DB -p $PGPORT HealthInterval=30s HealthTimeout=10s HealthStartPeriod=60s HealthRetries=3 # Share /run/postgresql/ between containers in the pod for the Unix socket Volume=/run/quadlets/postgresql:/var/run/postgresql:z [Service] Restart=always RestartSec=10 TimeoutStartSec=120 TimeoutStopSec=30 # These environment variables are sourced to be used by systemd in the Exec* commands EnvironmentFile=/etc/quadlets/postgresql/config.env [Install] WantedBy=postgresql.target