Accessing mysql running in another container by a Jar running in another container

Existing Environment:

  1. A server having the following packages installed
    Nginx, Mysql, Java, Redis.
  2. The server is having one jar file which uses the Mysql server for database support.
  3. The Mysql JDBC driver use localhost as the hostname in the URL.

In process of replicating the existing environment using Docker we perform the following tasks:

  • Unjustified increase of the image layers after ADD . sentences
  • How to build docker images on AWS EC2 Windows Server instance?
  • How to run a simple main method and copy the file it generated using docker
  • Container technologies: docker, rkt, orchestration, kubernetes, GKE and AWS Container Service
  • How to set password to a docker container
  • How to Give Docker Containers more resources
    1. Created four containers: nginx,redis,mysql and container running a Java application running in the same host.
    2. We have linked the container running the java application with the container mysql (which is already running mysql-server).
    3. After starting all the docker containers, when we get inside the container running the Java application and try to run the Java application we get the following error:

    Caused by: java.sql.SQLException: Access denied for user ‘application’@’172-17-0-7’ (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(

    Here the IP in the above exception is belong to the container running the jar and not the mysql container.

    Since the jar tries to connect the mysql server using the hostname as localhost via mysql jdbc driver we have changed the /etc/hosts file and made localhost point to the mysql container IP.

    Still, when we run the jar we are getting the same error.

    We are using bridge network. Can anybody let us know where may be the mistake from our side.

  • DockerHub set tag alias in automated build
  • Why docker containers can run, despite of docker-machine is not running?
  • How can I copy a config file within a Dockerfile?
  • docker swarm compose constraints
  • How to use docker remote api to create container?
  • How to enable Docker API access from Windows running Docker Toolbox (docker machine)
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.