How to access docker service with docker private ip and port from different host in aws without port forwarding or using docker host ip

I have the following setup, where both host are in same VPC.

Host1:

  • Docker - Enable Remote HTTP API with SystemD and “daemon.json”
  • Docker Swarm Cluster: daemonize
  • Pin ASP.Net 5.0 version to 'beta4' in Dockerfile
  • “kubectl exec” results in “error: unable to upgrade connection: Unauthorized”
  • How to upgrade docker container with previous network and volumes?
  • docker - local DNS
  •  public ip : 53.X.X.X 
     private ip : 172.X.X.X 
     docker ip : 173.16.42.1 (bridge ip)
    

    Host2:

     public ip : 53.X.X.X 
     private ip : 172.X.X.X
    

    Now, when I launch container from host1, let’s say tomcat, how can I access this server with private and port from Host2?

    I wanted like this from host2 173.16.42.2:8080.Added host1 nameserver in host2.

    Basically, I wanted this use case because I am using consul for service discovery, and in consul service are registered as 173.16.42.2:8080. But when I do nslookup tomcat.service.consul I am able to resolve the service ip and port. But when I do a telnet or curl for this ip”port it times out. Allowed all traffic and iptables rule between hosts.

    I am able to achive above usecase with port forwarding and accessing service using host ip.But i need the above approach 173.16.42.2:8080 from host2

    So any suggesation would be helpful

  • Proper way to automatically start and expose ssh when running my app container
  • Eclipse IDE within docker
  • User/pw/email Authentication for Cloudbees Docker Build and Deploy Jenkins plugin
  • Dockerfile: create ENV variable that a USER can see?
  • How to access Docker container's web server from host
  • How to install a minimal cuda driver file into Alpine linux
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.