0

Docker engine is running on AWS windows server 2016

Here is docker-compose.yml file

version: '3'
services:
     controllerdb:
            hostname: controllerdb
            image: <windows base mysql image>
            restart: always
     web:
            hostname: web
            depends_on: 
                - controllerdb
            image: <windows base tomcat image>
            restart: always
            ports:
                - 8080:8080
            links:
                - controllerdb
networks:
     default:
         external:
            name: nat
    

For connecting with database URL in tomcat

URL = jdbc:mysql://controllerdb:3306/database_name"

But on running compose file its giving error

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
 The last packet sent successfully to the server was 0 milliseconds ago. The driver has not 
 received any packets from the server.
 **Caused by: java.net.UnknownHostException: controllerdb**
 

Even after providing correct hostname , its giving UnknownHostException.

This connection work with linux container but I want to establish it in windows container.

Please , let me know how to fix it, So that inter container communication in windows containers can be done.

  • `links:` is an obsolete setting from first-generation Docker networking; does deleting that setting make any difference here? – David Maze Jul 06 '21 at 15:47
  • not it does not make any difference, error remains the same. – Gurpreet Singh Jul 06 '21 at 15:49
  • Are there any `networks:` settings in the file at all? ("No" is a good answer.) To confirm, the error you quote is a startup-time error from the `web` container coming from the `docker-compose up` output? Does the database container start up successfully? – David Maze Jul 06 '21 at 15:52
  • Its using default network of driver nat , and yes database is starting up successfully before the web container start. – Gurpreet Singh Jul 06 '21 at 16:03

1 Answers1

0
version: '3'
services:
     controllerdb:
            hostname: controllerdb
            image: <windows base mysql image>
            restart: always
            networks:
                - app-network
     web:
            hostname: web
            depends_on: 
                - controllerdb
            image: <windows base tomcat image>
            restart: always
            ports:
                - 8080:8080
            networks:
                - app-network
networks:
    app-network

the DNS for your database would be controllerdb:your-port,

paltaa
  • 2,985
  • 13
  • 28