Why is my jar throwing ‘No route to host exception’ when called from a Jenkins pipeline

  docker, jenkins, mysql, routes

I have a Jenkins job that should download my application jar from Nexus and run it on slave machine. My slave machine is a docker host and that application should import some data into MySQL database which runs in a docker container on my Jenkins slave host. When I run it from cmd on the host itself it works fine. But from Jenkins it gives me ‘No route to host’. I checked basically everything there is nothing wrong with networking the database is accessible from where ever I want, and I have an information that nothing is wrong with the code but I really didn’t checked it since I’m not a java developer. My Jenkins master and slave hosts are connected and the job brakes when the jar should be run against the database. I tried with pretty much everything I can find from networking and firewalls to testing java connection strings. And again nothing is wrong with the network and I really do not know anymore why it won’t run. Any hint would be helpful. And yes, I already tried time zone and locale settings on the docker host and the database. Here’s the full error stack trace.

15:46:40  com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
15:46:40    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
15:46:40    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
15:46:40    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
15:46:40    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
15:46:40    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
15:46:40    at com.mysql.jdbc.Util.getInstance(Util.java:381)
15:46:40    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
15:46:40    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
15:46:40    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
15:46:40    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2253)
15:46:40    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
15:46:40    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
15:46:40    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
15:46:40    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
15:46:40    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
15:46:40    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
15:46:40    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
15:46:40    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
15:46:40    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
15:46:40    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)
15:46:40    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
15:46:40    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735)
15:46:40    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667)
15:46:40    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482)
15:46:40    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
15:46:40    at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
15:46:40    at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
15:46:40    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)
15:46:40    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
15:46:40    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
15:46:40    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:326)
15:46:40    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:366)
15:46:40    at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)
15:46:40    at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139)
15:46:40    at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105)
15:46:40    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$cb890503.CGLIB$jpaVendorAdapter$9(<generated>)
15:46:40    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$cb890503$$FastClassBySpringCGLIB$$d19f35a6.invoke(<generated>)
15:46:40    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
15:46:40    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
15:46:40    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$cb890503.jpaVendorAdapter(<generated>)
15:46:40    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:46:40    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
15:46:40    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:46:40    at java.lang.reflect.Method.invoke(Method.java:498)
15:46:40    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
15:46:40    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
15:46:40    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
15:46:40    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
15:46:40    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
15:46:40    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
15:46:40    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
15:46:40    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
15:46:40    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
15:46:40    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
15:46:40    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
15:46:40    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
15:46:40    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
15:46:40    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
15:46:40    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
15:46:40    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
15:46:40    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
15:46:40    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
15:46:40    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
15:46:40    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
15:46:40    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
15:46:40    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
15:46:40    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
15:46:40    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
15:46:40    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
15:46:40    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
15:46:40    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
15:46:40    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
15:46:40    at com.realgarant.batch.Application.main(Application.java:35)
15:46:40    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:46:40    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
15:46:40    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:46:40    at java.lang.reflect.Method.invoke(Method.java:498)
15:46:40    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
15:46:40    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
15:46:40    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
15:46:40    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
15:46:40  Caused by: java.net.NoRouteToHostException: Keine Route zum Zielrechner (Host unreachable)
15:46:40    at java.net.PlainSocketImpl.socketConnect(Native Method)
15:46:40    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
15:46:40    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
15:46:40    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
15:46:40    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
15:46:40    at java.net.Socket.connect(Socket.java:589)
15:46:40    at java.net.Socket.connect(Socket.java:538)
15:46:40    at java.net.Socket.<init>(Socket.java:434)
15:46:40    at java.net.Socket.<init>(Socket.java:244)
15:46:40    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
15:46:40    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
15:46:40    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2177)
15:46:40    ... 90 common frames omitted```

Source: Docker Questions

LEAVE A COMMENT