making requests to localhost from inside docker container

I have an application runing on my localhost at port 8080. I have some python code that consumes that service. The code runs fine on my base system but as soon as I put it inside a docker container I get urllib2.URLError: <urlopen error [Errno 111] Connection refused>. I have another application that exposes an api at port 6543. Same problem.

I assume I need to tell docker that it’s allowed to consume certain localhost ports. How do I do that?

  • Can you have a docker copy in the same line as docker run
  • ERROR: for couchbase-db driver failed programming external connectivity
  • what does VOLUME command do in Dockerfile?
  • how to use pip to install pkg from requirement file without reinstall
  • elastic beanstalk application can't find private docker image
  • 502 Bad Gateway Error(Nginx as Docker container + Consul Docker run + Tomcat as a Docker container + Nomad)
  • Here are some more specific details:

    I can execute this line of code just fine on my base system:

    urllib2.urlopen(req, json.dumps(dData))

    but when I try to do it from inside a docker container then I get:

    File "/usr/lib/python2.7/", line 154, in urlopen
      return, data, timeout)
    File "/usr/lib/python2.7/", line 431, in open
      response = self._open(req, data)
    File "/usr/lib/python2.7/", line 449, in _open
      '_open', req)
    File "/usr/lib/python2.7/", line 409, in _call_chain
      result = func(*args)
    File "/usr/lib/python2.7/", line 1227, in http_open
      return self.do_open(httplib.HTTPConnection, req)
    File "/usr/lib/python2.7/", line 1197, in do_open
      raise URLError(err)
    urllib2.URLError: <urlopen error [Errno 111] Connection refused>

    I’ve tried adding permissions to docker.sock

    ls -l /var/run/docker.sock      
    => srw-rw-rwx 1 root docker 0 Feb 17 11:09 /var/run/docker.sock

  • docker-compose for artifactory and mysql images
  • How to POST InputStream as the body of a request in Retrofit?
  • move default docker container to another place on the disk
  • Docker-compose daemon exiting
  • Selecting different code branches when using a shared base image in Docker
  • Kibana on Docker cannot connect to Elasticsearch
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.