Deployment of a PostgreSQL instance in an isolated container, with data persistence on the host filesystem.
⚠️ This compose file is designed for PostgreSQL >= 18. For earlier versions, make sure to uncomment the appropriate variable in your.envfile. See the Configuration section for details.
- Podman
- podman-compose
- Linux host OS
.
├── .env # Environment variables file (to create, do not commit)
├── .gitignore
├── compose.yaml # PostgreSQL service definition
├── example.env # Environment file template
└── README.md
git clone git@github.com:ThomasDeOliv/postgresql-compose.git
cd postgresql-composeCopy example.env to .env at the root of the project, then edit the parameters according to your setup. All available variables and their roles are documented in example.env.
# Run from the project postgresql-compose directory
cp example.env .env
nano .env
# Edit the .env file and save your configuration
⚠️ Please, never commit the.envfile — it contains sensitive information.
# From the project postgresql-compose directory
podman-compose up -d# From the project postgresql-compose directory
podman-compose downThis compose file is also compatible with Docker.
| Parameter | Value | Description |
|---|---|---|
| Image | postgres:18.1 |
Default version. Can be overridden via PG_VERSION in .env |
| Port | 5432 |
Standard PostgreSQL port exposed on the host. Can be overridden via PG_HOST_DB_PORT in .env |
| Network | bridge |
Dedicated internal network for the service |
| Volume | bind mount | Data path defined via DB_DATA_PATH in .env |
:Z |
SELinux label | SELinux relabeling for Podman. Allows the container to access the bind mount on SELinux enforcing systems (Fedora, RHEL…). Harmless under Docker. |
restart: always |
— | Automatically restarts after a crash or reboot |
- The
.envfile must never be versioned. - In production, prefer a secrets manager (Vault, Podman secrets, Docker secrets).
- Restrict access to port
5432via a firewall if the database is not meant to be exposed on the network.
This project is released under the Unlicense.