Skip to content
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

Cannot host postgres ehrdb on other port then 5432 docker #1209

Closed
2 tasks done
SevKohler opened this issue Oct 31, 2023 · 4 comments
Closed
2 tasks done

Cannot host postgres ehrdb on other port then 5432 docker #1209

SevKohler opened this issue Oct 31, 2023 · 4 comments
Labels
invalid This doesn't seem right

Comments

@SevKohler
Copy link

Before reporting an issue

  • I have searched existing issues
  • I have reproduced the issue with the latest release

Environment information

latest everything

Steps to reproduce

run docker-compose with an postgres ehrdb on another port then 5432

Expected behavior

compose working

Actual result

connection refused on DB

docker-ehrbase-1  | SQL State  : 08001
docker-ehrbase-1  | Error Code : 0
docker-ehrbase-1  | Message    : Connection to ehrdb:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
docker-ehrbase-1  | 
docker-ehrbase-1  | 	at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:60)
docker-ehrbase-1  | 	at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:75)
docker-ehrbase-1  | 	at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:147)
docker-ehrbase-1  | 	at org.flywaydb.core.Flyway.migrate(Flyway.java:124)
docker-ehrbase-1  | 	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
docker-ehrbase-1  | 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
docker-ehrbase-1  | 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
docker-ehrbase-1  | 	... 122 common frames omitted
docker-ehrbase-1  | Caused by: org.postgresql.util.PSQLException: Connection to ehrdb:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Further information

#docker-compose-ehrbase.yml
version: '3'

services:
  ehrbase:
    image: ehrbase/ehrbase:next
    ports:
      - 8080:8080
    networks:
      - ehrbase-net
    environment:
      DB_URL: jdbc:postgresql://ehrdb:5433/ehrbase
      DB_USER_ADMIN: ehrbase
      DB_PASS_ADMIN: ehrbase
      SECURITY_AUTHTYPE: BASIC
      SECURITY_AUTHUSER: myuser
      SECURITY_AUTHPASSWORD: myPassword432
      SECURITY_AUTHADMINUSER: myadmin
      SECURITY_AUTHADMINPASSWORD: mySuperAwesomePassword123
      DB_USER: ehrbase_restricted
      DB_PASS: ehrbase_restricted
    depends_on:
      - ehrdb
    restart: on-failure

  ehrdb:
    image: ehrbase/ehrbase-postgres:latest
    ports:
      - 5433:5432
    networks:
      - ehrbase-net
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      EHRBASE_USER_ADMIN: ehrbase
      EHRBASE_PASSWORD_ADMIN: ehrbase
      EHRBASE_USER: ehrbase_restricted
      EHRBASE_PASSWORD: ehrbase_restricted

networks:
  ehrbase-net: {}

@SevKohler SevKohler added the bug Something isn't working label Oct 31, 2023
@SevKohler SevKohler changed the title Cannot host postgres ehrdb on other port then 54332 Cannot host postgres ehrdb on other port then 5432 Oct 31, 2023
@SevKohler SevKohler changed the title Cannot host postgres ehrdb on other port then 5432 Cannot host postgres ehrdb on other port then 5432 docker Oct 31, 2023
@SevKohler
Copy link
Author

SevKohler commented Oct 31, 2023

compose is copy pasted from the repo, only volume was removed, port changed and postgres version set to latest.
The Database is accessible via pgadmin.

@vidi42
Copy link
Contributor

vidi42 commented Nov 1, 2023

Triaged.
Internal reference number 1113

@vidi42
Copy link
Contributor

vidi42 commented Nov 1, 2023

@SevKohler looking a bit over your issue seems the problem is actually with the docker-compose :)

5433:5432 maps the exposes the container port (5432) to 5433 on the host machine, but doesn't change the port that the container runs against in the internal network.
jdbc:postgresql://ehrdb:5433/ehrbase won't work because Docker will try to connect to the ehrdb container through the internal network and on the internal Docker network ehrdb is still running against 5432.

If you just want to change the exposed port of ehrdb, you can leave the JDBC URL pointing to 5432, Docker will know how to handle it.
If you want to change the port that postgres runs against also on the internal Docker network, you need to do something like this https://stackoverflow.com/a/59572350

Here is a working docker-compose with the exposed port changed to 5433

version: '3'

services:
  ehrbase:
    image: ehrbase/ehrbase:next
    ports:
      - 8080:8080
    networks:
      - ehrbase-net
    environment:
#here the port stays the same
      DB_URL: jdbc:postgresql://ehrdb:5432/ehrbase
      DB_USER_ADMIN: ehrbase
      DB_PASS_ADMIN: ehrbase
      SECURITY_AUTHTYPE: BASIC
      SECURITY_AUTHUSER: myuser
      SECURITY_AUTHPASSWORD: myPassword432
      SECURITY_AUTHADMINUSER: myadmin
      SECURITY_AUTHADMINPASSWORD: mySuperAwesomePassword123
      DB_USER: ehrbase_restricted
      DB_PASS: ehrbase_restricted
      
    depends_on:
      - ehrdb
    restart: on-failure

  ehrdb:
    image: ehrbase/ehrbase-postgres:latest
    ports:
#only changed this part
      - 5433:5432
    networks:
      - ehrbase-net
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      EHRBASE_USER_ADMIN: ehrbase
      EHRBASE_PASSWORD_ADMIN: ehrbase
      EHRBASE_USER: ehrbase_restricted
      EHRBASE_PASSWORD: ehrbase_restricted

networks:
  ehrbase-net: {}

@vidi42 vidi42 added feedback Feedback from the creator of the issue is required and removed bug Something isn't working labels Nov 1, 2023
@SevKohler
Copy link
Author

SevKohler commented Nov 1, 2023

Oh my, your totally correct my bad !
You can close the issue, thanks for the help !

@vidi42 vidi42 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2023
@vidi42 vidi42 added invalid This doesn't seem right and removed feedback Feedback from the creator of the issue is required labels Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants