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 ?

  • Multiple SymmetricDS instances at same host
  • Windows Server 2016 Docker - cant install webfarm components to microsoft/iis image
  • docker registry with --insecure-registry and docker 1.5
  • Rails assets fingerprints differ on server
  • “Docker-compose up” does not pull images everytime , it recreates a pulled image
  • Run a maven webapp in a docker container
  • Delete logs of containers docker for mac
  • Cannot start service php-fpm: invalid header field value "oci runtime error: container_linux.go:247: starting container
  • Configure Dancer from environment variables?
  • Run Docker in daemon mode
  • Docker's container mount folder
  • 404 page on Docker when installing
  • 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.