Skip to content

Instantly share code, notes, and snippets.

@citizenrich
Created July 1, 2020 18:31
Show Gist options
  • Save citizenrich/ef644ea195106a771717e8c234e525b3 to your computer and use it in GitHub Desktop.
Save citizenrich/ef644ea195106a771717e8c234e525b3 to your computer and use it in GitHub Desktop.
How to setup HAPI FHIR and Postgres in Docker

Start with a fresh folder and copy a hapi.properties into it. It will be mounted into the container.

Carefully make sure your hapi.properties looks like this:

# add postgres
datasource.driver=org.postgresql.Driver
datasource.url=jdbc:postgresql://db:5432/hapi
hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
datasource.username=admin
datasource.password=admin
# comment out derby
# datasource.driver=org.h2.Driver
# datasource.url=jdbc:h2:file:./target/database/h2
# datasource.username=
# datasource.password=

...
###################################################
# Database Settings
###################################################
# comment this out
# hibernate.dialect=org.hibernate.dialect.H2Dialect

Add the docker-compose below, and docker-compose up. Visit: http://localhost:8080/hapi-fhir-jpaserver/

To troubleshoot:

  • Database stuff: Connect to the database at localhost:5432 using your tool of choice with user admin, pass admin, and to db hapi. Obviously, don't use the same settings in production.
  • HAPI: Run docker ps to get your container id. Then run commands you need to in the running container like: docker exec <containerid> /bin/bash -c 'cat /usr/local/tomcat/conf/hapi.properties
version: "3"
services:
hapi-fhir-jpaserver-start:
image: hapiproject/hapi:v4.2.0
container_name: hapi-fhir-jpaserver-start
restart: on-failure
ports:
- "8080:8080"
environment:
- JAVA_OPTS='-Dhapi.properties=/usr/local/tomcat/conf/hapi.properties'
volumes:
- ./hapi.properties:/usr/local/tomcat/conf/hapi.properties
depends_on:
- db
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: admin
POSTGRES_USER: admin
POSTGRES_DB: hapi
# not needed for networking between containers but here for troubleshooting
ports:
- "5432:5432"
@keerthivasan-r
Copy link

Does it comes hapiproject/hapi:v4.2.0 bundled with tomcat server? Please clarify.

@citizenrich
Copy link
Author

@keerthivasan-r
Copy link

Awesome. Thank you!

@citizenrich
Copy link
Author

citizenrich commented Oct 20, 2020

For those coming to this gist, it has been superseded in HAPI v5.1 by the application.yml file, and no longer uses hapi.properties

This works for v5.1. There is no need to edit any file or mount it. The environment vars work fine.

version: '3'

services:

  fhir:
    container_name: fhir
    image: hapiproject/hapi:v5.3.0
    ports:
      - "8080:8080"
    environment:
      profiles.active: r4
      spring.datasource.url: 'jdbc:postgresql://db:5432/hapi'
      spring.datasource.username: admin
      spring.datasource.password: admin
      spring.datasource.driverClassName: org.postgresql.Driver
      # - "tester.server_address=http://localhost:8080/fhir"
    depends_on:
      - db

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: admin
      POSTGRES_USER: admin
      POSTGRES_DB: hapi
    # not needed for networking between containers but here for troubleshooting
    ports:
      - "5432:5432"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment