Yuki
Yuki

Reputation: 4173

docker domain/port mapping to localhost

I am using docker-compose and one of my containers makes requests to domain.name.com:443 (cannot be changed) that is not accessible from the host. There is a tunnel on localhost:542 that holds this endpoint on the host. Can I map this somehow in the docker compose or use some workarounds?

Kind of domain.name.com:443:542 that requests from domain.name.com:443 from the container arrive to localhost:542.

Upvotes: 1

Views: 2099

Answers (1)

LMC
LMC

Reputation: 12672

You can add an entry on container's /etc/hosts file mapping that domain to your host's IP address

docker run -it --add-host "parent.example.com:192.168.0.2" --network="host" --rm busybox

Test from container with:

/ # cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.0.2     parent.example.com

/ # wget -q http://parent.example.com:8000 -O -

response from parent.example.com:8000

In my case, I tested on the host running a minimal web server

 while true ; do { echo -e "HTTP/1.1 200 OK\r\nConnection: Close\r\n\r\n"; echo "response from parent.example.com:8000" ; } | netcat -q 0 -l 8000 ;done

Your mapping should be --add-host "domain.name.com:<your_ip_address>". The ssh tunnel should be made on port 443, not 542.

Upvotes: 1

Related Questions