Docker: How to curl local server running on host machine from within a docker container

On my host machine, I have a server running on nginx. It is not dockerized and not accessible to the outside world, it is simply used for local dev environment.

I would like to be able to access it from within a docker container.

  • How to remove docker installed using wget? [closed]
  • How to create read-only user in the Docker Registry v2?
  • Build a full Ubuntu desktop docker image
  • Docker container cannot run
  • Docker - Multiple duplicate volume declarations; what happens?
  • Docker mount directories to container rules
  • For example, I’d like to be able to do the following from within my docker container:


    and to see the same output I see when I run the command on my host machine.

    Also, I am using docker-compose.

  • Docker push re-sends layers to private repository
  • Need help on docker scaling of micro-services
  • Docker proper redirect link
  • What are Selenium Docker image release versions for browser capabilities?
  • Why isn't my Dockerfile's ARG expanded?
  • Connect to a docker host that is managed by dockercloud-agent
  • 2 Solutions collect form web for “Docker: How to curl local server running on host machine from within a docker container”

    It’s probably not routing directly to the host’s network. This question may help.

    I guess your container doesn’t know about your because It is declared in your host’s /etc/host (you said it is a private server)?

    Then you could add the host as extra_host:

          - ""

    The extra_host will add hostname mappings in container’s /etc/host.

    And run your docker-compose.yml replacing HOST_BRIDGE_IP with it’s ip in docker bridge:

    HOST_BRIDGE_IP=$(docker network inspect bridge \
      --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}') \
    && sed -e "s/HOST_BRIDGE_IP/${HOST_BRIDGE_IP}/g" \
    docker-compose.yml | docker-compose --file - up

    This would allow virtual host resolution based on DNS in your server.

    Edit: This seems a bit overkill to me, anyone has a better suggestion?

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