HAPI FHIR with Docker Compose and PostgreSQL: when a team needs this setup
A team needs this setup when it must run a self-hosted FHIR server inside its own infrastructure and wants a stack that can be rebuilt the same way on a laptop, a test host or a single production host. The HAPI FHIR JPA server starter defaults to an embedded H2 database, which is convenient for a first look but is not where patient data should live. PostgreSQL is one of the supported production databases, and Microsoft SQL Server is the other, so a Compose file that pairs the server with a PostgreSQL service is the usual next step after a single-container trial. The starter can be deployed as the hapiproject/hapi Docker image, with Docker Compose, with Spring Boot, as a WAR on Tomcat, Jetty or Wildfly, or on Kubernetes with a Helm chart, so Compose is a deliberate choice for a single-host or pre-production stack rather than the only option.
What the Compose file adds over a plain container is the set of pieces that make the stack repeatable: a database service with its credentials supplied from outside the file, named volumes so data survives container rebuilds, health checks that let dependent services wait for the database, custom interceptors mounted into the container, and startup installs of implementation guides. Each of these is a decision the team owns. Confirm which PostgreSQL major version your organization will standardize on, since support windows differ by release, and check the HAPI FHIR release notes for the JDK requirement of the image tag you pin. A pinned image and a pinned database version are what make a rebuild reproducible.
The main risk is treating the Compose stack as production because it works on one host. A single host has no database replication, no automatic failover and no built-in backup routine, so the team must plan backups, restore tests and a recovery path before go-live. The Compose setup also does not add the access control, audit logging or TLS that a clinical or regulated deployment requires; those sit in front of or inside the server and need their own design. Ask whoever will operate the stack to confirm the controls, retention and hosting location in writing before patient-like data is loaded.
Compose services, volumes and trust boundaries
Traffic starts at a client outside the host and reaches the operator's reverse proxy, which is the operator's responsibility to configure and secure. The proxy forwards requests to the HAPI FHIR container, which talks to the PostgreSQL service only over the internal Compose network. The database files sit on a named volume, and configuration, the custom interceptor JAR and the implementation guide package are mounted read-only into the HAPI container. Check that PostgreSQL is not published to the host network, that mounts are limited to what the server needs, and that the proxy terminates TLS.
Request path, database link, storage and mounted files for the Compose stack.
Configuration options and when each fits
This table compares the choices that shape a Compose stack for HAPI FHIR and PostgreSQL: how configuration is supplied, how database settings are handled, how data is stored, and when implementation guides are installed. Read each row for the condition under which it fits and the cost it carries, then confirm exact keys and defaults in the starter and image documentation.
| Decision | Option | When it fits | Trade-off |
|---|---|---|---|
| Configuration source | Environment variables in the Compose file | Small changes such as the database URL, credentials passed from an env file and a few toggles | Long lists become hard to review, and values are visible in container inspection output |
| Configuration source | Mounted application.yaml | Many settings, enabled modules and interceptor references that the team wants under version control | The file must match the image version, and mismatches show up at startup rather than at build time |
| PostgreSQL connection | Dedicated database and role per HAPI FHIR instance | Separate environments or tenants that need isolated credentials and backups | More roles and passwords to rotate and track in the Compose secrets process |
| PostgreSQL connection | Connection pool sizing in the HAPI configuration | Expected concurrent requests are known and the team has load-tested the stack | Pool size that is too large can exhaust PostgreSQL connection limits; confirm the pool keys in the starter documentation |
| PostgreSQL connection | PgBouncer between HAPI FHIR and PostgreSQL | Many application instances or a need to cap server-side connections | Another service to configure, monitor and upgrade; confirm compatibility with the HAPI pool settings first |
| Data storage | Named Docker volumes for PostgreSQL data | Single-host development or pilot stacks where Docker manages the storage location | Harder to see and back up directly from the host, so backup jobs must target the volume explicitly |
| Data storage | Bind mounts to host directories | Teams that need the data directory on a specific disk, filesystem or backup path they already manage | Ownership and permissions of the host directory must match the PostgreSQL user inside the container |
| Implementation guides | Install IG packages at startup through configuration | Fixed, tested guide versions that should be present on every fresh environment | Startup takes longer and depends on package availability, so pin versions and test restarts |
| Implementation guides | Load IG packages after the server is running | Guides change on a different schedule from the server, or the team wants to control timing of each load | Adds a manual or scripted step, and the environment is incomplete until it runs |
Setup sequence for the Compose stack
This sequence takes an empty host to a Compose stack in which HAPI FHIR runs against PostgreSQL with persistent storage, health checks, mounted interceptors and an installed implementation guide. Each step closes with a check so the next one starts from a known state.
Pin the image tags and PostgreSQL major version
Choose a HAPI FHIR image tag from the hapiproject/hapi image and pin it exactly, so the server does not change on the next pull. Choose a PostgreSQL major version that is still supported: 18 (final release November 14, 2030), 17 (to November 8, 2029), 16 (to November 9, 2028), 15 (to November 11, 2027) or 14 (to November 12, 2026). Confirm the HAPI FHIR tag's Java requirement against the versions documentation, since 8.2.0 requires JDK 17 and later releases may differ. Check: the compose file contains two fixed image references and no
latesttags.Define the PostgreSQL service and its credentials
Add a
dbservice using the pinned PostgreSQL image, with the database name, user and password supplied from Docker secrets or an env file kept out of version control, not typed inline in the compose file. Restrict the service to the internal Compose network and do not publish port 5432 to the host unless an administrator needs it. Check:docker compose configrenders the password as a secret reference or file path, anddocker compose up dbstarts the database and accepts a local connection with the supplied user.Configure the HAPI service datasource and driver
Add an
hapiservice that depends on the database and sets the datasource URL, username and password through environment variables that point at thedbservice name. Set the PostgreSQL driver mode in the starter configuration and confirm the key names against the starter's application.yaml documentation for your pinned version. The starter defaults to embedded H2, so the PostgreSQL setting must be explicit. Check: the HAPI container logs show a connection to PostgreSQL, not H2, during startup.Add persistent volumes for both services
Declare named volumes for the PostgreSQL data directory and, if you use file-based storage, for any HAPI FHIR working files, so data survives container recreation. Keep the database volume separate from the application volume so each can be backed up on its own schedule. Check: after
docker compose downanddocker compose up, a test resource created earlier still returns from the server.Add health checks for the database and server
Add a
pg_isreadyhealth check to the database service and a health check to the HAPI service that calls the actuator health endpoint, then setdepends_onwith a condition that waits for the database to be healthy. Allow a longer start period for the HAPI service, because schema creation runs on first start. Check:docker compose psshows both services as healthy, and the HAPI service does not report unhealthy during its first schema migration.Mount interceptors and the implementation guide configuration
Mount your compiled custom interceptor JAR and any implementation guide configuration into the container paths the pinned image reads at startup, using read-only bind mounts where possible. Set the implementation guide install setting in the configuration so the package installs when the server starts, and confirm the package name and version against the implementation guide documentation you intend to use. Check: startup logs list the mounted interceptor as loaded and the implementation guide as installed, with no classpath or package errors.
Verify the metadata endpoint and database connection
Request the server's capability statement at the
/metadatapath through the published port and confirm the FHIR version matches the one you configured. Then open a shell in the database container and run a query that lists the HAPI schema tables, which shows the server wrote to PostgreSQL. Record the image tags, PostgreSQL version and mounted files in your change record. Check:/metadatareturns a CapabilityStatement with the expected FHIR version, and the table query returns HAPI tables.
Mounting custom interceptors and installing an implementation guide at startup
Build the interceptor against the same HAPI FHIR version that the container runs. A custom interceptor reaches the server as compiled classes on its classpath, so the work starts in a build project that depends on the HAPI FHIR version pinned in your Compose file. Package the interceptor class into a JAR and mount that JAR into the container with a volume, at a path the starter's classpath loader reads. The FHIR version the server runs also matters, because resource model classes differ across DSTU2, DSTU3, R4, R4B and R5, so an interceptor written for one version may not load or behave correctly on another. The HAPI FHIR versions page states that 8.2.0 requires JDK 17. Confirm the JDK requirement for the version you pin, and build any custom code with that JDK.
Registration happens through the starter's Spring configuration, and the exact key names depend on the starter release you pin. Confirm them against the hapi-fhir-jpaserver-starter repository before you write the Compose file. Keep the mounted application.yaml, the interceptor JAR path and the interceptor's own settings, such as which resource types it guards, in files you can review and version together. Implementation guide packages are installed the same way: the starter reads IG entries from configuration during startup, so the package must be reachable from the container or from a source the server can fetch. Confirm the key names, IG version and load order for your release, and test the install on both an empty PostgreSQL volume and an existing one.
Check the server logs after each start for interceptor registration and IG load messages. Then query the server's CapabilityStatement and fetch a profile from the guide to confirm the IG is available. Test every change on a non-production copy first, because an interceptor that fails during startup can stop the server from starting. Record the interceptor JAR version, the IG package version and the HAPI FHIR image tag together, so the same combination can be rebuilt and reproduced when you upgrade.
Security and operational considerations for the Compose stack
HAPI FHIR and PostgreSQL ship building blocks, not a finished security posture, so the controls around the Compose stack are your responsibility. The cards below cover the application layer, the database layer, the network edge, secrets, backups and logs, and each one needs an owner and a test before go-live.
Application authorization and consent
HAPI FHIR states that it does not provide a single security layer. It offers authentication interceptors, the AuthorizationInterceptor, consent and search narrowing interceptors and CORS support, and you must choose and wire these yourself. Decide which roles may read, write or delete each resource type, and test that a token for one role cannot reach another role's data. Confirm how interceptors are loaded into the container before you rely on them.
HAPI FHIR security docsAudit logging with BALP
BALP audit logging records who accessed which FHIR resources and when, and it is one of the building blocks the HAPI FHIR security documentation lists. Enable it deliberately and decide where audit records are stored, since the Compose stack has no audit store by default. Check that a read of a patient record produces an entry you can query, and that failed authorization attempts are also recorded.
PostgreSQL authentication and SCRAM
PostgreSQL documents several client authentication methods, including password, certificate, LDAP and OAuth. Set password_encryption to scram-sha-256 and use SCRAM for the HAPI FHIR database role in pg_hba.conf, because PostgreSQL 18 has deprecated MD5 password authentication in favor of SCRAM. Give the application a role with only the privileges it needs, and restrict host entries to the Compose network.
TLS termination at the edge
The HAPI FHIR container listens on plain HTTP inside the Compose network unless you configure TLS directly. Place a reverse proxy or load balancer in front of the server to terminate TLS, and set the public server address so that links and Bundle entries use HTTPS. Decide whether traffic between the proxy and the container is also encrypted, and confirm that the database connection is protected in transit according to your policy.
Secrets outside the Compose file
Database passwords and any OAuth client secrets should not appear in docker-compose.yml or in a committed application.yaml. Use environment files excluded from version control, Docker secrets or a secrets manager that your organization already operates, and rotate credentials on a schedule you document. Check the running container's environment with a single inspect command, because values passed as variables are visible to anyone who can read the container configuration.
Volume backups and restore tests
The PostgreSQL data directory lives in a named volume, and a copy of that volume is not a tested backup on its own. Schedule logical dumps or continuous archiving with point-in-time recovery, store copies outside the host, and restore them into a separate Compose project. Record how long a restore takes and whether the HAPI FHIR server starts cleanly against the restored schema.
Continuous archiving docsLog retention and failure response
Container logs are rotated by the Docker logging driver unless you configure a limit, and short retention can erase the evidence an incident review needs. Set a log driver with size and file limits, forward logs to a store you control, and agree on a retention period with your compliance team. PostgreSQL does not detect primary failure by itself, so write down who is paged when the database container stops.
Questions buyers ask before setting up HAPI FHIR with Compose and PostgreSQL
Is Docker Compose production-ready for a HAPI FHIR server?
Compose is a reasonable way to build, test and run a single-host environment, but it does not by itself give you high availability, rolling upgrades across nodes or the scheduling features of an orchestrator. The HAPI FHIR JPA starter can run in Docker, with Compose, or on Kubernetes with a Helm chart, and the production design depends on your availability targets, your hosting model and your operations staff. Before you treat a Compose stack as production, confirm how backups, certificate renewal, log retention and restores will run, and whether your hosting team supports Compose at all.
What changes when we move from Compose to Kubernetes?
The application configuration stays largely the same, but the operational model changes. Kubernetes adds probes, rolling deployments, secrets objects, ingress and pod disruption budgets, and it needs a cluster you already operate or are willing to build. The Helm chart offers bundled or external PostgreSQL, and the choice between them is a design decision with backup, upgrade and failover consequences. Ask the quote to separate the Compose work from any cluster build so the two costs are not mixed.
Can our own team set up HAPI FHIR with Compose and PostgreSQL?
Yes, if your team has container experience, can manage a PostgreSQL database and understands Java application configuration. The effort is mostly in decisions rather than typing: the database settings, persistent volumes, the FHIR version, the interceptors you mount, and how the implementation guide is installed at startup. The part teams most often underestimate is ongoing ownership, including patching the image, planning upgrades, testing restores and reviewing security controls. HAPI FHIR states it does not provide a single one-size-fits-all security layer, so authentication, authorization and audit logging must be designed by you.
What do we need to provide before a partner starts the work?
A partner needs access to the infrastructure where the stack will run, whether that is a cloud account, a virtual machine or a data center host, along with a named technical contact and a decision-maker for sign-off. You should also classify the data the server will hold, because that decides the controls around storage, encryption, logging and retention. If the server will use single sign-on, the identity provider owner must provide configuration details and test accounts. Agree in writing who approves the final configuration and the go-live checks.
How long does this work take?
The duration depends on scope rather than on the Compose file alone. A local or test stack with a single PostgreSQL instance is far shorter than one that includes an implementation guide, custom interceptors, identity integration, backups and a review of security settings. No fixed duration is stated here. Ask the quote for a timeline broken into phases, with the dependencies on your infrastructure access, identity provider and approvals shown, and the points where your team must respond.
What drives the cost of this work up or down?
Cost is driven by the number of environments, the number of custom interceptors and their complexity, the implementation guides to install and validate, the identity and access model, the database design and the level of documentation and handover. Costs that recur include patching, upgrades, backup testing and support. Ask a quote to show one-time work separately from recurring support, to name who pays for infrastructure, licenses and third-party services, and to state what is excluded, such as load testing or security testing.
How does PostgreSQL affect the safety of this setup?
PostgreSQL is released under a liberal open source license, and its supported major versions currently run through 2030 for version 18, which gives you a long planning horizon. Compose will not provide failover, so the database needs its own plan for backups, point-in-time recovery and, if required, a standby server. PostgreSQL does not include software to detect a primary failure and notify the standby, so automatic failover needs external tools. Confirm the backup and restore procedure with your team before go-live.
Keeping the PostgreSQL database and HAPI FHIR current
PostgreSQL maintenance and HAPI FHIR upgrades run on different cycles, and the Compose file is where they meet. Treat the PostgreSQL image tag and the hapiproject/hapi tag as two separately pinned versions, each changed through its own tested step. Minor PostgreSQL releases never change the internal storage format, so applying one means replacing the executables and restarting the container with the same data volume. That is a routine change you can schedule without a data migration. Major versions are different: the supported windows in the facts run from PostgreSQL 14 (to November 12, 2026) through PostgreSQL 18 (to November 14, 2030), and once a major version leaves support you need to plan its successor before the end date, not after.
Major upgrades use pg_dumpall and restore, pg_upgrade, or logical replication. For a Compose stack, a dump and restore into a new volume is the simplest path to rehearse, while logical replication, which works across major versions with only several seconds of downtime according to the PostgreSQL upgrading documentation, suits stacks where the outage window is tight. Confirm which method your team can operate, and remember that the HAPI FHIR schema and the PostgreSQL major version must both be supported by the chosen HAPI FHIR release. Check the HAPI FHIR upgrade notes before changing either, because a HAPI FHIR upgrade may run schema migrations on startup that you cannot easily reverse.
Backups and point-in-time recovery must be tested, not assumed. Restoring a dump into a scratch Compose project, starting the matching HAPI FHIR tag against it, and running a few representative searches is the minimum proof that a backup is usable. If you rely on continuous archiving for point-in-time recovery, restore to a chosen timestamp and confirm the resource counts and history match what you expect. Record the time each restore takes, since that figure is the one your recovery plan actually depends on, and confirm it with your own data volume rather than relying on a generic estimate.
How DeployOpen scopes and delivers a HAPI FHIR Compose and PostgreSQL setup
DeployOpen plans, builds and documents HAPI FHIR JPA server stacks with Docker Compose and PostgreSQL inside infrastructure you control. The work starts with a written scope that fixes the deliverables, then moves through a tested build, a handover your team can operate, and optional ongoing support.
How we scope
- Written scope covers the HAPI FHIR version, FHIR resource versions and enabled modules for your server
- Scope records the PostgreSQL version, volume layout, backup targets and the network boundary around the stack
- Scope names the custom interceptors and implementation guides to mount or install, with their owners and review steps
How we build
- Compose file is built with pinned image tags, a PostgreSQL service, named volumes and health checks for each service
- Interceptors are mounted into the container and tested against sample requests before they reach a shared environment
- Implementation guide installation at startup is verified on a clean database, including a repeat start against existing data
How we hand over
- Handover includes the Compose project, environment file layout, configuration notes and a runbook for start, stop and restore
- Documentation covers how to replace the image tag, rerun the database backup check and read health status
- Your team receives a test record showing the startup, persistence and restart checks that were run before handover
How we support
- Engagements are fixed-scope, and any follow-on changes are agreed in writing before work starts
- Ongoing support, upgrades and continuous testing are available as a retainer, scoped to your Compose environment
- Upgrade planning covers HAPI FHIR and PostgreSQL version changes, with a confirmation step against the supplied release notes

