TDN169
TDN169

Reputation: 1427

Access host port as localhost from docker

I have two machines connected via SSH tunnelling such that machine1:2222 can access machine2:2222 as localhost. machine2 runs the container docker2 and exposes services on port 2222 to localhost only. I can access these from machine1 on port 2222.

I would like to be able to access machine1:2222 from docker1, a container running on machine1 as localhost. I can determine the gateway IP address from within docker1, however connections are rejected because they come from the IP address assigned to docker1 rather than localhost.

So, what is the best way to access services on machine2 from docker1 on machine1? Solutions I've seen seem to involve modifying iptables on the host machine which doesn't seem all that portable.

Upvotes: 0

Views: 265

Answers (1)

TDN169
TDN169

Reputation: 1427

This is what the --net flag is for:

user@machine1:/ docker run --net="host" -ti docker1 /bin/bash

root@machine1:/ wget localhost:2222
>> (this will download whatever a request to machine2:2222 provides)

Upvotes: 1

Related Questions