Docker Community Forums

Share and learn in the Docker community.

Connection refused - two Docker Container

Hello, folks.

I am new to Docker and am currently trying to deploy two containers with a Docker-Compose file.
One contains the JBoss server with the application, the other the database.
The database is created during deploy and data is written to the database during deploy. But I get the message afterwards:
Caused by: org.h2.jdbc.JdbcSQLException: Connection is broken: “java.net.ConnectException: Connection refused: localhost:1521” [90067-182]

My Compose File:

version: ‘3’
services:
h2-dev:
container_name: ‘h2_database_V6’
build: “./nag_database”
hostname: ‘h2’
restart: always
image: oscarfonts/h2
ports:
- “81:81”
- “1521:1521”
volumes:
- h2-data:/opt/h2-data
nag-elm:
container_name: “nag_elm_core”
build: “./nag_elm”
restart: always
environment:
- DB_NAME=elm-database-nag-v6
- DB_USER={db-username} - DB_PASS={db-password}
- DB_PORT=81
- DB_HOST=h2-dev
ports:
- “8080:8080” # application
- “9990:9990” # admin console
- “8787:8787” # debug
depends_on:
- “h2-dev”
volumes:
- /opt/jboss/wildfly/log/:/opt/jboss/wildfly/standalone/log/ # wildfly logs
volumes:
h2-data:
#END

JBoss Dockerfile:

FROM jboss/wildfly:10.1.0.Final
ADD XY-6.0.0-SNAPSHOT.ear /opt/jboss/wildfly/standalone/deployments/

H2 Dockerfile

FROM openjdk:10

ENV DOWNLOAD http://www.h2database.com/h2-2018-03-18.zip
ENV DATA_DIR /opt/h2-data

RUN mkdir -p {DATA_DIR} \ && curl {DOWNLOAD} -o h2.zip
&& unzip h2.zip -d /opt/
&& rm h2.zip

COPY h2.server.properties /root/.h2.server.properties

EXPOSE 81 1521

WORKDIR /opt/h2-data

CMD java -cp /opt/h2/bin/h2*.jar org.h2.tools.Server
-web -webAllowOthers -webPort 81
-tcp -tcpAllowOthers -tcpPort 1521
-baseDir ${DATA_DIR}

EDIT
If i run my Application on IntelliJ locally and the Database in the Docker Container, it works!
But not in the pair Docker-Docker

Thanks for help!
Chris