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 ?

  • Exposing docker container on local server
  • Docker: Can different containers use different base Images?
  • How to compile from a remote machine ?
  • handle docker container data while developing wep application
  • Switching users inside Docker image to a non-root user
  • How to run docker on mac offline
  • Docker NGINX Proxy not Forwarding Websockets
  • How can I set an overlay network within docker compose
  • docker error Unable to locate package cowsay
  • Unable to install docker
  • Docker-compose shuts down container starting a different one
  • docker deploy vs docker stack deploy
  • 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.