0

I am trying to run a grails app in docker and keep running in some mysql connection problems. I can't figure out where the problem is.

This is my docker-compose file

version: "2"
   services:
      db:
       image: mysql:5.7
      volumes:
       - db_data:/var/lib/mysql
      restart: always
      environment:
          MYSQL_ROOT_PASSWORD: root2017
          MYSQL_DATABASE: dbname
          MYSQL_USER: Dbuser
          MYSQL_PASSWORD: passw
 grails:
   depends_on:
     - db
   ports:
     - "9001:9001"
   restart: always
   environment:
     DB_HOST: db:3306
     DB_PASSWORD: passw
volumes:
    db_data:

The grails app does not start with the following error:

ERROR 18:08:05 org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool. grails_1 | com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Torsten
  • 722
  • 6
  • 30
  • Possible duplicate of [How do I know when my docker mysql container is up and mysql is ready for taking queries?](http://stackoverflow.com/questions/25503412/how-do-i-know-when-my-docker-mysql-container-is-up-and-mysql-is-ready-for-taking) – nwinkler Mar 30 '17 at 06:22
  • This is likely caused by the database not being available at the point where your Java app starts. Please take a look at the linked question, it contains several solutions for waiting for the database to be up. I use https://github.com/vishnubob/wait-for-it for this purpose. – nwinkler Mar 30 '17 at 06:24
  • Thanks, but my problem was that i changed passwords in the compose file, since its mounted to the volume I had to delete the volume in order to set the new passwords. – Torsten Mar 30 '17 at 14:40

1 Answers1

0

You will need to configure your datasource to point to "jdbc:mysql://db:3306/dbname"

You can do this with external config file for production env. Or you can read the values for host and db name from system environments.

See Deploying grails application war to tomcat with docker and docker compose

Sudhir N
  • 4,008
  • 1
  • 22
  • 32