0

On my host machine, I have a server xyz.example.com 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.

For example, I'd like to be able to do the following from within my docker container:

curl xyz.example.com

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

Also, I am using docker-compose.

dipole_moment
  • 5,266
  • 4
  • 39
  • 55

2 Answers2

3

I guess your container doesn't know about your xyz.example.com 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:

services:
  some-service:
    extra_hosts:
      - "xyz.example.com:HOST_BRIDGE_IP"

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?

François Maturel
  • 5,884
  • 6
  • 45
  • 50
0

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

MattP
  • 1,920
  • 1
  • 15
  • 22