Connection docker Mysql (Hibernate)

Hello. New to docker and the forum. I have a Java app running with JavaSpark framework (I send a request to the Facebook Api and save the data on a my db) I run this localy and works perfect. The problem is when I try to make this happens on my docker containers (I have one container for the app and another for the Mysql DB).

Here my docker-compose.yml:

karma:
  build: .
  command: java -jar target/server-0.0.1-jar-with-dependencies.jar
  ports:
    - "8081:8081"
  volumes:
    - ./:/app/karma
  links:
      - db:db

db:
  image: mysql:5.7
  environment:
    MYSQL_ROOT_PASSWORD: karma
    MYSQL_DATABASE: karma
    MYSQL_USER: karma
    MYSQL_PASSWORD: karma
  ports:
    - "3306:3306"
  volumes:
    - ./:/app/

Here my hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://db:3306/karma</property>
        <property name="hibernate.connection.username">karma</property>
        <property name="hibernate.connection.password">karma</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">create-drop</property>
        <mapping resource="com/hibernate/FbData.hbm.xml"></mapping>
    </session-factory>
</hibernate-configuration>

When I send the request to the app (on docker) it throw an connection error:

java.lang.ExceptionInInitializerError
       at com.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
       at com.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:7)
       at com.server.server.Server.lambda$main$0(Server.java:37)
       at spark.RouteImpl$1.handle(RouteImpl.java:61)
       at spark.http.matching.Routes.execute(Routes.java:61)
       at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:130)
       at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
       at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
       at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
       at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
       at org.eclipse.jetty.server.Server.handle(Server.java:517)
       at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
       at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
       at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
       at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
       at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
       at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
       at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
       at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
       at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
       at java.lang.Thread.run(Thread.java:745)
 Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
       at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
       at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
       at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
       at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
       at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
       at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
       at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
       at com.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
       ... 20 more
 Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
       at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
       at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:101)
       at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
       at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
       at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
       at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:123)
       at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:42)
       at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:20)
       at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161)
       at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:109)
       at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:72)
       at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
       at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
       at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
       at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
       at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
       at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257)
       ... 34 more
 Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

 The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
       at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:988)
       at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
       at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251)
       at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
       at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
       at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
       at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
       at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
       at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
       at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
       ... 49 more
 Caused by: java.net.ConnectException: Connection refused (Connection refused)
       at java.net.PlainSocketImpl.socketConnect(Native Method)
       at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
       at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
       at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
       at java.net.Socket.connect(Socket.java:589)
       at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
       at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
       ... 62 more

Anyone know how to fix this? I have already past one week fixing this bug and I cant get it :frowning:

Thanks in advance !!

Hi,

I am facing same issue. Could you resolve it? if so please post it.

Thanks

By default MySQL ( and postgres and mongo) do not allow connecting from outside their environment. The container is another system from mysql’s perspective. So u have to enable remote connections. Read the MySQL doc for this, or the instructions of the DB image u are using

Hi,

Here is the docker-compose.yml file

version: '3'


services:


 mysql_server:
  image: mysql/mysql-server:5.7
  environment:
   MYSQL_ROOT_PASSWORD: root  
  ports:
   - "3306:3306"
  volumes:
   - "./WeatherStation_NGAC_Server_Docker:/docker-entrypoint-initdb.d/"

 java8:
  image: openjdk:8-jre

 weather_station_app:
  build:
   context: .
   dockerfile: Dockerfile_1
  ports:
   - "5684:5684"
  links:
   - mysql_server
   - java8

and Dockerfile_1

FROM openjdk:8-jre
WORKDIR /
ENV MYSQL_ROOT_PASSWORD=root
ADD WeatherStation_NGAC_Server_Docker/target/WeatherStation_NGAC_Server_Docker-0.0.1-SNAPSHOT-jar-with-dependencies.jar server.jar
ADD WeatherStation_NGAC_Server_Docker/resources resources
ADD WeatherStation_NGAC_Server_Docker WeatherStation_NGAC_Server_Docker
CMD "java" "-jar" "server.jar"

and my hibernate_cfg.xml

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://mysql_server:3306/policydb_ngac?useSSL=false</property>
		<property name="hibernate.connection.verifyServerCertificate">false</property>
        <property name="hibernate.connection.requireSSL">false</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
    <property name="hibernate.show_sql">false</property>
    <mapping resource="node.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

and the exception i get is

weather_station_app_1  | Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
weather_station_app_1  | 	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
weather_station_app_1  | 	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
weather_station_app_1  | 	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
weather_station_app_1  | 	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
weather_station_app_1  | 	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
weather_station_app_1  | 	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
weather_station_app_1  | 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
weather_station_app_1  | 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.ngac_database.DatabaseManager.<init>(DatabaseManager.java:36)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.Declarations.add_nodeTypes(Declarations.java:45)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.Server.createNodes(Server.java:76)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.Server.main(Server.java:47)
weather_station_app_1  | Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
weather_station_app_1  | 	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:101)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:106)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:40)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:19)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:138)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:110)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:74)
weather_station_app_1  | 	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
weather_station_app_1  | 	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
weather_station_app_1  | 	... 17 more
weather_station_app_1  | Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
weather_station_app_1  | 
weather_station_app_1  | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
weather_station_app_1  | 	at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:590)
weather_station_app_1  | 	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:57)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1606)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:633)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347)
weather_station_app_1  | 	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
weather_station_app_1  | 	... 32 more
weather_station_app_1  | Caused by: com.mysql.cj.core.exceptions.CJCommunicationsException: Communications link failure
weather_station_app_1  | 
weather_station_app_1  | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
weather_station_app_1  | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
weather_station_app_1  | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
weather_station_app_1  | 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
weather_station_app_1  | 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:93)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:133)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:149)
weather_station_app_1  | 	at com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:83)
weather_station_app_1  | 	at com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:122)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1726)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1596)
weather_station_app_1  | 	... 36 more
weather_station_app_1  | Caused by: java.net.ConnectException: Connection refused (Connection refused)
weather_station_app_1  | 	at java.net.PlainSocketImpl.socketConnect(Native Method)
weather_station_app_1  | 	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
weather_station_app_1  | 	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
weather_station_app_1  | 	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
weather_station_app_1  | 	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
weather_station_app_1  | 	at java.net.Socket.connect(Socket.java:589)
weather_station_app_1  | 	at com.mysql.cj.core.io.StandardSocketFactory.connect(StandardSocketFactory.java:202)
weather_station_app_1  | 	at com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:57)
weather_station_app_1  | 	... 39 more

I don’t really get any good source on Internet, to set mysql server to allow remote connections. I read on Internet that using link in yml file will add the mysql server details to the current service. Can you help me with a good source? I am struggling with this for almost a week.

Hi, I tried to make a .sql script with privileges. When I give the command docker-compose up , I see that the application is starting before the mysql server. I guess that might be the reason for exception as it can’t find a MySQL server. Any comments on how to fix this.

Pulling mysql_server (mysql/mysql-server:5.7)...
5.7: Pulling from mysql/mysql-server
4040fe120662: Pull complete
d049aa45d358: Pull complete
a6c7ed00840d: Pull complete
853789d8032e: Pull complete
Digest: sha256:1b4c7c24df07fa89cdb7fe1c2eb94fbd2c7bd84ac14bd1779e3dec79f75f37c5
Status: Downloaded newer image for mysql/mysql-server:5.7
Pulling java8 (openjdk:8-jre)...
8-jre: Pulling from library/openjdk
3e731ddb7fc9: Pull complete
47cafa6a79d0: Pull complete
79fcf5a213c7: Pull complete
fd532571c5d3: Pull complete
31600c9f9b48: Pull complete
78e8e9b5d10e: Pull complete
0710e619e883: Pull complete
e511da65ffab: Pull complete
Digest: sha256:e88b6ea0b459268c7f80f9c7a60c73ed33c9b369f23bf0ada4fcca6161fe6c6d
Status: Downloaded newer image for openjdk:8-jre
Building weather_station_app
Step 1/7 : FROM openjdk:8-jre
 ---> e956268fd4ed
Step 2/7 : WORKDIR /
Removing intermediate container 5602762ffe74
 ---> 5f2ae6263b53
Step 3/7 : ENV MYSQL_ROOT_PASSWORD=root
 ---> Running in f04950eaef9a
Removing intermediate container f04950eaef9a
 ---> 570a6259b5de
Step 4/7 : ADD WeatherStation_NGAC_Server_Docker/target/WeatherStation_NGAC_Server-0.0.1-SNAPSHOT-jar-with-dependencies.jar server.jar
 ---> bcf30266feda
Step 5/7 : ADD WeatherStation_NGAC_Server_Docker/resources resources
 ---> 9c67036dd0a3
Step 6/7 : ADD WeatherStation_NGAC_Server_Docker WeatherStation_NGAC_Server_Docker
 ---> 2ef05110581a
Step 7/7 : CMD "java" "-jar" "server.jar"
 ---> Running in 7854ccdb9608
Removing intermediate container 7854ccdb9608
 ---> de199765203d
Successfully built de199765203d
Successfully tagged javaexample_weather_station_app:latest
WARNING: Image for service weather_station_app was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose Creating javaexample_mysql_server_1        ... done
Creating javaexample_java8_1               ... done
Creating javaexample_java8_1               ... 
Creating javaexample_weather_station_app_1 ... done
Attaching to javaexample_java8_1, javaexample_mysql_server_1, javaexample_weather_station_app_1
javaexample_java8_1 exited with code 0
mysql_server_1         | [Entrypoint] MySQL Docker Image 5.7.21-1.1.4
mysql_server_1         | [Entrypoint] Initializing database
weather_station_app_1  | Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
mysql_server_1         | [Entrypoint] Database initialized
weather_station_app_1  | Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
weather_station_app_1  | 	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
weather_station_app_1  | 	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
weather_station_app_1  | 	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
weather_station_app_1  | 	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
weather_station_app_1  | 	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
weather_station_app_1  | 	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
weather_station_app_1  | 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
weather_station_app_1  | 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.ngac_database.DatabaseManager.<init>(DatabaseManager.java:36)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.Declarations.add_nodeTypes(Declarations.java:45)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.Server.createNodes(Server.java:76)
weather_station_app_1  | 	at com.WSServer.WeatherStation_NGAC_Server.Server.main(Server.java:47)
weather_station_app_1  | Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
weather_station_app_1  | 	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:101)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:106)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:40)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:19)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:138)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:110)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:74)
weather_station_app_1  | 	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
weather_station_app_1  | 	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
weather_station_app_1  | 	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
weather_station_app_1  | 	... 17 more
weather_station_app_1  | Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
weather_station_app_1  | 
weather_station_app_1  | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
weather_station_app_1  | 	at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:590)
weather_station_app_1  | 	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:57)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1606)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:633)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347)
weather_station_app_1  | 	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)
weather_station_app_1  | 	at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
weather_station_app_1  | 	... 32 more
weather_station_app_1  | Caused by: com.mysql.cj.core.exceptions.CJCommunicationsException: Communications link failure
weather_station_app_1  | 
weather_station_app_1  | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
weather_station_app_1  | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
weather_station_app_1  | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
weather_station_app_1  | 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
weather_station_app_1  | 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:93)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:133)
weather_station_app_1  | 	at com.mysql.cj.core.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:149)
weather_station_app_1  | 	at com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:83)
weather_station_app_1  | 	at com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:122)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1726)
weather_station_app_1  | 	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1596)
weather_station_app_1  | 	... 36 more
weather_station_app_1  | Caused by: java.net.ConnectException: Connection refused (Connection refused)
weather_station_app_1  | 	at java.net.PlainSocketImpl.socketConnect(Native Method)
weather_station_app_1  | 	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
weather_station_app_1  | 	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
weather_station_app_1  | 	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
weather_station_app_1  | 	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
weather_station_app_1  | 	at java.net.Socket.connect(Socket.java:589)
weather_station_app_1  | 	at com.mysql.cj.core.io.StandardSocketFactory.connect(StandardSocketFactory.java:202)
weather_station_app_1  | 	at com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:57)
weather_station_app_1  | 	... 39 more
javaexample_weather_station_app_1 exited with code 1
mysql_server_1         | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql_server_1         | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
mysql_server_1         | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
mysql_server_1         | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
mysql_server_1         | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
mysql_server_1         | 
mysql_server_1         | [Entrypoint] ignoring /docker-entrypoint-initdb.d/Californium.properties
mysql_server_1         | 
mysql_server_1         | [Entrypoint] running /docker-entrypoint-initdb.d/accountingdb.sql
mysql_server_1         | 
mysql_server_1         | 
mysql_server_1         | [Entrypoint] running /docker-entrypoint-initdb.d/policydb.sql
mysql_server_1         | 
mysql_server_1         | 
mysql_server_1         | [Entrypoint] ignoring /docker-entrypoint-initdb.d/pom.xml
mysql_server_1         | 
mysql_server_1         | [Entrypoint] ignoring /docker-entrypoint-initdb.d/resources
mysql_server_1         | 
mysql_server_1         | [Entrypoint] ignoring /docker-entrypoint-initdb.d/server.log
mysql_server_1         | 
mysql_server_1         | [Entrypoint] ignoring /docker-entrypoint-initdb.d/src
mysql_server_1         | 
mysql_server_1         | [Entrypoint] running /docker-entrypoint-initdb.d/startup.sql
mysql_server_1         | 
mysql_server_1         | 
mysql_server_1         | [Entrypoint] ignoring /docker-entrypoint-initdb.d/target
mysql_server_1         | 
mysql_server_1         | [Entrypoint] Server shut down
mysql_server_1         | 
mysql_server_1         | [Entrypoint] MySQL init process done. Ready for start up.
mysql_server_1         | 
mysql_server_1         | [Entrypoint] Starting MySQL 5.7.21-1.1.4

Hi,

It is resolved now. i tried to add

depends_on: 
 - mysql_server

in docker-compose.yml file. Also, the server execution is made to sleep until the mysql is up and running.