B
B
BorisT2016-07-23 22:57:10
Domain Name System
BorisT, 2016-07-23 22:57:10

How to assign an IP (hostname) to a Docker container?

How to assign an IP to a container so that it can be accessed from the host system (mac, Docker for mac)?
When trying to do something like

docker run --name postgres -d -p 172.17.42.1:5432:5432 postgres

says: Error response from daemon: driver failed programming external connectivity on endpoint postgres (d3b1656ba...): Error starting userland proxy: listen tcp 172.17.42.1:5432: bind: cannot assign requested address.
Which, of course, is probably due to the absence of the docker0 bridge, which is mentioned in the documentation . But for some reason, Docker for mac does not create it (tried to reset it). I tried to create a new network (docker network create...), but also ifconfig does not show any new interfaces.
Binds on 127.0.0.1 (-p 5432:5432) without problems, but it's not very convenient.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max's altinbatir11, 2020-02-05
@altinbatir11

Good time. Faced the same problem. I would like to share the solution to this problem.
1. Disable virtualization of TCP IP protocols in Chios (not the fact that this is the case), but I enabled this option.
2. No need to write 172/17/42/1:5432 write 127/0/0/1:5432 but this is on docker release 2/20. On release 1/19, this method does not work and a crutch is needed in the form of iptables example 192/168/1/102:5432 since I use a router and set up the following table. The nat_wormations section under the virtuls_servise menu forwards ports to the IP we need (I repeat docker platforms 1/19), this scheme will not work on platform 2/20. This bug has been fixed in platform 2/20.
Good luck to all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question