Stream: implementers
Topic: hapi fhir + docker + MySQL
Traven (Mar 27 2021 at 20:59):
Hi everyone
We are trying to set up a HAPI FHIR Server with docker and connected to a MySQL Docker and are getting the error
"com.myslql.cj.jdbc.exception.CommunicationException: Communicationlink failure"
error.log
Anyone an idea?
Further infos if needed:
---> What is working
-> Start HAPI FHIR without config file (docker run -p 8080:8080 -e hapi.fhir.default_encoding=xml hapiproject/hapi)
-> Start HAPI FHIR with default config file (https://github.com/hapifhir/hapi-fhir-jpaserver-starter/blob/master/src/main/resources/application.yaml)
-> Check if mysql database is created console-output-mysql.txt
---> What is NOT working
-> Start HAPI FHIR with following changes in config file
url: 'jdbc:mysql://localhost:3306/hapi_dstu3' (the database has already been created)
driverClassName: com.mysql.cj.jdbc.Driver
starting with comand: docker run -p 8080:8080 --name happy2 -v /home/ubuntu/HAPI_FHIR:/configs -e "--spring.config.location=file:///configs/application.yaml" hapiproject/hapi:latest
Lloyd McKenzie (Mar 28 2021 at 02:30):
@James Agnew
Aditya Kurkure (Mar 28 2021 at 04:35):
@Traven
url: 'jdbc:mysql://localhost:3306/hapi_dstu3'
the localhost here would mean that the SQL server is located in the same container as HAPI FHIR sever. If you are using the same docker compose file for running both MYSQL and HAPI then you'll need to change the localhost
to your mysql container name. Otherwise if the mysql container's port is mapped to a port on the host machine you'll need to use the hosts IP address instead of localhost
Jens Villadsen (Mar 28 2021 at 06:33):
This isn't really an error. By design the docker uses H2 defaulting to a file-based database (the in-mem variant is also listed in the config file), which works fine inside docker. It gets you quicly up and running. If you need real persistence like eg. MySQL, then you need to change the defaults, and yes, then you need to point to an adress outside the docker container hosting the hapi-fhir-jpaserver-starter. This is entirely as intended an also very much in line with scoping services in Docker. The configurations listed at https://github.com/hapifhir/hapi-fhir-jpaserver-starter#mysql-configuration does not take into account that you are running it in Docker which is a choice of your own.
Richard Stanley (Mar 28 2021 at 17:56):
Also note that you can now provide env vars to HAPI to change the config without editing it directly.
Traven (Mar 30 2021 at 18:24):
Thanks alot -> this was indeed our problem and after getting the right ip of the mysql docker it all worked. Big shout-out to @Aditya Kurkure , @Jens Villadsen and the rest of this super helpful community!
Last updated: Apr 12 2022 at 19:14 UTC