Access to localhost from docker container

I want to access to a local webserver that is outside the docker container.

I have a testsuite (casperjs) inside a docker container that open a browser to localhost:8002/etc, but “localhost” here refers to my local machine, not something inside the docker container. How can I achieve that ?

  • I can't access mounted volume of docker-postgres from host
  • How to get the URL of Swarm agent load balancer in Azure container service
  • Elastic Beanstalk Docker App fails after “Restart App Servers”
  • mounting external drives to a Docker container
  • Docker build leads to “no space left on device” on Windows 10
  • io.fabric8 docker-maven-plugin error: “No config type given”
  • Monit not clearing the pid file and restarting a process when the process becomes a zombie
  • Address a Multi Manager Swarm cluster
  • How to configure docker registry always up and running when configured with redis?
  • Launch a Docker container with a Windows Scheduled Task
  • do not change directory if gitbash is started by docker quickstart terminal shortcut
  • docker run can't find application
  • One Solution collect form web for “Access to localhost from docker container”

    You would have to use the IP of the bridge to get to the host. Docker usually is deployed the other way around though. You’d have a service inside a container beint used from outside it… (thus casperJS inside the container being hit from the host)

    Or you could have the original webserver in a container and --link it into the casper container and utilize the host name of the webserver container:

    docker run -p 80 --name app {your image} start
    docker run --link app:app {your casperjs} start
    

    and utilize the hostname “app” for accessing the webserver.

    Hope this helps!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.