Accessing external hosts from docker container

I am trying to dockerize my application. I have two servers, say server1 and server2. Server1 uses webservice hosted on server2. I have this in my
/etc/default/docker on server1:

DOCKER_OPTS="--dns --dns --iptables=false" 

As I understand this prevents docker from making any changes to iptables, overriding UFW settings. The UFW status shows this:

  • Is there a way to set scale value before fig up?
  • Communicating with a Solr 4.10 container in docker-compose
  • Nginx in Docker container gets `connection reset` error, but works fine without a container
  • manage more than one Elasticsearch container with docker-compose
  • Is it possible to run android emulator / android apps in docker?
  • Docker mount directory access rights
  • Status: active
    To                         Action      From
    --                         ------      ----
    22                         ALLOW       Anywhere
    443                        ALLOW       Anywhere
    2375/tcp                   ALLOW       Anywhere
    22 (v6)                    ALLOW       Anywhere (v6)
    443 (v6)                   ALLOW       Anywhere (v6)
    2375/tcp (v6)              ALLOW       Anywhere (v6)

    Now the trouble is I am not able to access server2 from my app which runs
    in a container on server1. If I don’t use the –iptables=false flag then I can access server2. What can I do to access server2 from the container without having to sacrifice UFW ?

    If it matters , both server1 and server2 are on digitalocean and have private networking enabled.

  • docker-compose : Unsupported config option for services service: 'web'
  • Docker images/containers taking up space despite clean up
  • The requested URL returned error: 502 when running git clone inside a Docker container
  • Where store an API Token for Jenkins used in Dockerfile
  • Dockerfile fails to build
  • Running nginx as non-root in Docker container gives permission denied error
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.