Unable to Connect MySQL container to Tomcat Container in docker

The Plan

I want my tomcat server to be able to connect to my MySQL server both in separate containers.

  • Throttling Disk Utilization
  • aws ecs perfomance doesn't increase on single instance
  • Docker : using pv (pipe viwer) output nothing on build process
  • Host as Pid namespace in Docker
  • Docker compose up fails with `require': cannot load such file — rack/handler/rails (LoadError)
  • Symfony2 app always has a 3 second wait between kernel.request and kernel.controller
  • The Problem

    Tomcat cannot connect to MySQL

    I used some of the details from the wordpress tutorial about setting up a link with the mysql container and created the link to the MySQL.

    Although the tomcat and mysql spin up just fine I can’t seem to get tomcat to be able to connect to MySQL, the settings work on my local machine perfectly fine.

    I’ve attempted to use --net: "host" as well although that does not work with Tomcat as it throws a severe error.

    Previous answers

    I noticed on this post a load of possible fixes for the error although I don’t believe any of these would translate to my problem as I believe this is a docker problem not a host one.


      image: tomcat:7.0
      container_name: tomcat-container
       - "80:8080"
      hostname: docker-tomcat
       - /home/webapps:/usr/local/tomcat/webapps
       - db
      image: mysql
      container_name: mysql-container
       MYSQL_ROOT_PASSWORD: Mysqlpassword1
       MYSQL_DATABASE: tracker
       - /home/mysqlDB:/var/lib/mysql

    This is my Context.xml from tomcat.

            name="jdbc/tracker" type="javax.sql.DataSource"
            maxActive="100" maxIdle="30" maxWait="10000" 
            username="root" password="mysqladmin1"
            name="jdbc/jenkins" type="javax.sql.DataSource"
            maxActive="100" maxIdle="30" maxWait="10000" 
            username="root" password="mysqladmin1"

    The error code.

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at databaseConnections.SQLDatabaseConnection.tableExists(SQLDatabaseConnection.java:131)
    at databaseConnections.JiraSQLDatabaseConnection.<init>(JiraSQLDatabaseConnection.java:50)

  • InsecurePlatformWarning when building Docker image
  • What is the reporitory name when add docker task in Bamboo?
  • Running docker commands in bash script leads to segmentation fault
  • How to start another bash in Dockerfile
  • Get 502 Bad Gateway when use fastcgi_pass:
  • Docker+SSH, how to transfer docker images from one host to another securely on a regular basis?
  • One Solution collect form web for “Unable to Connect MySQL container to Tomcat Container in docker”

    As you’re linking db as “db”, you cannot use localhost to join you database. you should “db”


    In your container, localhost design your tomcat container, not your host. MySQL container has his own network.

    Futhermore, if you don’t like “db” name, you can name link it with different name

    For exemple:

       - db:container-mysql

    In this case, inside you tomcat container, you could use

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.