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:

  • Docker/nginx [windows10] - change page on linked folder and show changes directly in the browser
  • Why does Docker “ancestry” API command not work?
  • Docker cloud: weave cannot join the network
  • How to delete the HDFS data in Docker containers
  • Running app inside Docker as non-root user
  • Setting up Nginx Proxy in Docker using Ansible
    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(SQLError.java:998)

    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.

  • docker websphere can't get the admin console
  • Updating Short and Full Descriptions on Docker Hub
  • Get list of containers/services of docker-compose from inside a container
  • DockerToolbox for win7 service unavailable error
  • AWS Gogs deployment using Docker image
  • docker insecure registry daemon not using flag
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.