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 8.8.8.8 --dns 8.8.4.4 --iptables=false" 

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

  • Docker does not auto update DNS server details in /etc/resolv.conf
  • Data is lost in Mysql docker container after comminting it to a new image?
  • docker run from systemd service starts but exits immediately, and restarts, but docker run from shell works fine
  • Build Docker image of a Python Flask app
  • Unable to push a plugin using docker plugin push command
  • Azure ARM Template dependsOn: How to reference a VM extension?
  • 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 build error with vue-cli Webpack boilerplate
  • Cannot connect externally to a docker container running CherryPy server
  • Import images from kitematic to boot2docker
  • How to tell Docker client location of Notary Server?
  • Unable to connect docker nginx with docker ubuntu
  • Possible to run two instances of docker containers on one mysql database container?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.