UberJar cant connect to mysql on docker

I have 2 dockers: openjdk with mysql. I am able to run mysql -h mysql57 -u root -p from the openjdk successfully.
when running the docker-compose I am getting:

web_1      | ERROR: Cannot check and update database. See the stacktrace below for details.
web_1      | Caused by: com.haulmont.cuba.core.sys.DbInitializationException: Error connecting to database: Cannot create PoolableConnectionFactory (Communications link failure
web_1      | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
web_1      | Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure

(full error: JustPaste.it - Share Text & Images the Easy Way)

I have the following jetty config:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="CubaDS" class="org.eclipse.jetty.plus.jndi.Resource">
            <New class="org.apache.commons.dbcp2.BasicDataSource">
                <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
                <Set name="url">jdbc:mysql://mysql57/crmdev?useSSL=false&amp;allowMultiQueries=true&amp;serverTimezone=UTC&amp;allowPublicKeyRetrieval=true</Set>
                <Set name="username">root</Set>
                <Set name="password">rootPassword</Set>
                <Set name="maxIdle">2</Set>
                <Set name="maxTotal">20</Set>
                <Set name="maxWaitMillis">5000</Set>


task buildUberJar(type: CubaUberJarBuilding) {
    singleJar = true
    coreJettyEnvPath = 'modules/core/web/META-INF/jetty-env.xml'
    appProperties = ['cuba.automaticDatabaseUpdate' : true]

docker compose:

version: '2'

    image: mysql:5.7
    restart: unless-stopped
    container_name: mysql57
      - "3357:3306"
        MYSQL_ROOT_PASSWORD: rootPassword
        MYSQL_DATABASE: crmdev

    build: .
     - "8080:8080"
      - mysql57

(I just deployed the jar, I assume the env file is wrapped inside).
I have configured a new database in a remote machine, and still its not working, same error.

Here is a repository with the docker folder GitHub - avifatal/cuba-docker just run gradle build uber and copy the file to docker dir. docker-compose up


I have tried to reproduce the error on your github project. But it works.
I have only changed docker file to:

### Dockerfile

FROM openjdk:8
COPY . /usr/src/cuba
CMD java -Dapp.home=/usr/src/cuba/home -jar /usr/src/cuba/app.jar

Without app.home container couldn’t start with another error (persistence xml file cannot created).

Docker version: 18.09.1 and docker-compose version: 1.23.2

1 Like