I've created a Docker image to host a Scala application, where the application loads its database-connection information from a
properties file located in its directory:
driverClassName=org.postgresql.Driver jdbcUri=jdbc:postgresql://localhost:5432/pedscreen user=$APP_USER password=$APP_PASSWORD
I've also created a Docker image to host a Postgres database.
The docker-compose.yaml file:
version: "3.7" services: database: image: postgres:9.6.22 container_name: "postgres" environment: POSTGRES_PASSWORD: 'XXXXXXXXXX' volumes: - ./postgres/initdb:/docker-entrypoint-initdb.d/ ports: - '5432:5432' restart: unless-stopped app: image: scala-app:latest container_name: "scala-app" depends_on: - database
Unfortunately, the application isn't able to connect to the database, because the address
localhost isn't correct.
I thought about using an environment variable (
DATABASE_HOST) in the
driverClassName=org.postgresql.Driver jdbcUri=jdbc:postgresql://$DATABASE_HOST:5432/pedscreen user=$APP_USER password=$APP_PASSWORD
and populating it in the
... app: image: scala-app:latest container_name: "scala-app" environment: DATABASE_HOST: database depends_on: - database
But this doesn't work either:
... Caused by: org.postgresql.util.PSQLException: The connection attempt failed. ... Caused by: java.net.UnknownHostException: $DATABASE_HOST
Is there a way to get this to work?
I don't have any ability to modify the Scala application itself.