W
W
wasserbord2018-05-18 09:55:57
linux
wasserbord, 2018-05-18 09:55:57

Docker - how to forward port from host to container without --net=host?

A server is running on the host - let it be port 1234.
From the host to localhost: 1234, you can connect to it without problems.
However, it does not leave the container.
And if you enable --net=host, then other features of this program in the container (client) stop working. Therefore, a more accurate approach is needed.
Already install iptables in docker
docker exec golos-default /bin/bash -c "apt-get update"
docker exec golos-default /bin/bash -c "apt-get install -y iptables"
Then did this:
docker exec golos -default /bin/bash -c "iptables -t nat -A PREROUTING -p tcp --dport 1234 -j DNAT --to-destination 172.17.0.2:1234"
What is 172.17.0.2 is the result of ip route show | grep docker0 running on the host machine.
How to make in Ubuntu (preferably without tunnels) that the application (client) when trying to connect to ip1:port connects to ip2:port ?
True, here's another moment
netstat -tlnp
...
tcp 0 0 127.0.0.1:27017
This is on the host.
This is problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
planc, 2018-05-18
@planc

hang the service on 172.17.0.1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question