-
Notifications
You must be signed in to change notification settings - Fork 977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't build Postgres changes or connect to container #599
Comments
Did you create a database called |
I'm not super familiar with how the images are published, but does the image published as hapiproject/hapi:latest contain Postgres? There is a docker-compose.yml in this project which does, but is that what is published? |
No, it does not provide another DB other than imbedded H2.
|
I don't think that would work then. That localhost referenced in the application.yaml would be localhost to the docker container running HAPI, not the windows host. |
@csaun , if you are running a completely separate Postgres container and mapping port 5432 back to your Windows localhost, you'd need to figure out how to reference the windows host. This might point in the right direction: https://stackoverflow.com/questions/40746453/how-to-connect-to-docker-host-from-container-on-windows-10-docker-for-windows. If this is just for testing purposes, you might try using the docker-compose.yml file in this project to stand up a container with both HAPI and Postgres. You could then expose 5432 as well as 8080 from that to connect to the Postgres DB. NOTE this DB would not be permanent, not suitable for production, etc. |
Thanks for all the suggestions, unfortunately I'm still stuck :( 1) hapi-fhir-postgres ContainerI modified the application.yaml so that it points to the postgres docker container. datasource: Deleted the existing container then ran these cmds - This creates the 2 containers for the server (hapi-fhir-jpastarter-start) and postgres (hapi-fhir-postgres) This caused no errors but I don't know if the data is being saved in the original h2 db or somewhere in the postgres container. Is there a way to access and view the table data stored in the container or volume? To check if it's empty or not? Connecting to the Postgres Container **Long Message: Details: Stack Trace: This makes me think the data is being saved to the h2 embedded db and not the volume listed in the docker-compose 2) Localhost hapiWhen the project was cloned a postgres image was also pulled, the db service uses that postgres image. I thought this was enough and that I didn't have to create another hapi db locally.
hapi-fhir-jpaserver-start | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restfulServer' defined in class path resource [ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.class]: Unsatisfied dependency expressed through method 'restfulServer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySystemDaoR4': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: HAPI_PU] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution |
Your db visualizer app running on windows is not going to know how to resolve the hostname "hapi-fhir-postgres". That's not a hostname your windows environment knows about - it is local only to the docker container. You can probably port-forward 5432 from the Docker container to Windows - then you can connect your db visualizer app on localhost:5432 from windows. (Same as you are port forwarding port 8080 so you can issue http requests to the HAPI server on localhost:8080). If you want to just verify is the data getting saved into postgres, another option for troubleshooting is to connect to the docker container console. I don't know the precise syntax, but something like 'docker exec -it thecontainername sh' might work. Then once inside the container, you can run command-line 'psql' commands to connect to the DB, issue queries, etc. |
Ah ok thanks I didn't realise that it couldn't see the container's hostname. **In DBVisualizer I changed the Database Server to localhost but it says the database hapi does not exist. Baffling! ** An error occurred while establishing the connection: Long Message: Details: Stack Trace: This is the docker-compose.yml hapi-fhir-postgres: application.yaml file -> url: 'jdbc:postgresql:https://172.19.0.2:5432/hapi'
jpa:
hibernate.hbm2ddl.auto: updatehibernate.jdbc.batch_size: 20hibernate.cache.use_query_cache: falsehibernate.cache.use_second_level_cache: falsehibernate.cache.use_structured_entries: falsehibernate.cache.use_minimal_puts: falseThese settings will enable fulltext search with lucene or elastic
lucene parametershibernate.search.backend.type: lucenehibernate.search.backend.analysis.configurer: ca.uhn.fhir.jpa.search.HapiHSearchAnalysisConfigurers$HapiLuceneAnalysisConfigurerhibernate.search.backend.directory.type: local-filesystemhibernate.search.backend.directory.root: target/lucenefileshibernate.search.backend.lucene_version: lucene_currentelastic parameters ===> see also elasticsearch section below <===hibernate.search.backend.type: elasticsearchhibernate.search.backend.analysis.configurer: ca.uhn.fhir.jpa.search.HapiHSearchAnalysisConfigurers$HapiElasticAnalysisConfigurerhapi:
bulk_export_enabled: truesubscription:resthook_enabled: truewebsocket_enabled: falseemail:from: [email protected]host: google.comport:username:password:auth:startTlsEnable:startTlsRequired:quitWait:lastn_enabled: truestore_resource_in_lucene_index_enabled: trueThis is configuration for normalized quantity search level default is 00: NORMALIZED_QUANTITY_SEARCH_NOT_SUPPORTED - default1: NORMALIZED_QUANTITY_STORAGE_SUPPORTED2: NORMALIZED_QUANTITY_SEARCH_SUPPORTEDnormalized_quantity_search_level: 2#elasticsearch: debug:pretty_print_json_log: falserefresh_after_write: falseenabled: falsepassword: SomePasswordrequired_index_status: YELLOWrest_url: 'localhost:9200'protocol: 'http'schema_management_strategy: CREATEusername: SomeUsername` |
Seems like progress. What about connecting to the default 'postgres' database? |
From DBVisualizer I can connect to a db with the name postgres but if I use hapi as the db name it says it does not exist. Database Server: localhost When I connect to the postgres db there are only default pg tables, no FHIR data or tables. I'd expect there to be an hfj_resources table with the data I've posted to the server. I removed the postgres volume from docker as I thought this might be stopping it from creating the hapi db. Also deleted the containers and images. Then rebuilt using docker-compose up but it still doesn't seem to be creating the db. Surely docker-compose up should run the changes I made to the docker-compose and application.yaml files? Build Log There's no mention of a hapi db in the log file within Docker Desktop |
It is strange. While connected to the postgres database, you might be able to query to see what other databases are created, might point to a clue. Or, you can connect to the command line of the postgres docker container and and then run command-line psql commands to interrogate it. Might be some help here on the psql commands: https://dba.stackexchange.com/questions/1285/how-do-i-list-all-databases-and-tables-using-psql |
I'm unable to connect to the Postgres container using an external program like DBVisualizer. I changed the application.yaml file so it uses postgres not H2, then ran the project.
I'm new to Docker so didn't realise the code changes wouldn't be reflected in the postgres container as it's an instance of the original image. So I'm assuming even though the postgres container is running it's empty as any data posted to the server is actually be stored in the H2 db? So even if I could connect to the container there wouldn't be anything there?
I've now copied the application.yaml file and placed it in an external folder.
It's set to use postgres and port 5432 instead of H2 and uses localhost.
``datasource:
url: 'jdbc:postgresql:https://localhost:5432/hapi'
username: admin
password: admin
driverClassName: org.postgresql.Driver`
Connection Error
When I run the project that now uses the external version of the application.yaml file I get a 'Connection to localhost:5432 refused error. I'm on Windows and have turned the firewall and antivirus off.
Run cmd ->
docker run -p 8080:8080 -v C:\pathtofile\my-configs:/configs -e "SPRING_CONFIG_LOCATION=file:https:///configs/application.yaml" hapiproject/hapi:latest
Connection Error ->
2023-10-17 13:15:36.690 [main] INFO com.zaxxer.hikari.HikariDataSource [HikariDataSource.java:110] HikariPool-1 - Starting...
2023-10-17 13:15:37.696 [main] ERROR com.zaxxer.hikari.pool.HikariPool [HikariPool.java:594] HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:319)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.(PgConnection.java:247)
at org.postgresql.Driver.makeConnection(Driver.java:434)
at org.postgresql.Driver.connect(Driver.java:291)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:100)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
Is there a step I've missed? Should I be using that mvn install -DskipTests command somewhere as well so it doesn't run the original H2 integration tests?
The text was updated successfully, but these errors were encountered: