Is it possible to setup static IP address for container using Fig?
Hey Guys,
I have 2 apps api and frontend, each of them in separated docker container. Apps talk between each other using host names (api.my_app.com and frontend.my_app.com). Containers have an internal network and an IP address and I can setup it in /etc/hosts on local via:
172.17.0.74 api.my_app.com
172.17.0.75 frontend.my_app.com
My problem is when the box restart (fig up --no-recreate) my container loses its IP, and i have to reset the url in /etc/hosts each time after fig up. Is it possible to setup static IP address for container?
Thanks for any help.
@RuslanHamidullin I think this is impossible by design now. For auto-set hosts in /etc/hosts you can use docker links, but you still will be needed to restart both containers. In next release of docker /etc/hosts will be autoupdating.
@LK4D4 thanks, will checkout docker links
I'll toss in another vote for this. I'm trying to make compose work with Consul, and not being able to hardcode the IP address of a Consul server seems to be essential. Maybe I'll find a workaround but if I could start the Consul container with a specific IP instead of having one randomly assigned it would make life much much easier.
This is currently not possible, because it's not supported by Docker. In most cases, links should work (as explained, an entry will be added to /etc/hosts in the linked container, and kept in sync with the container.
If you really need a fixed / manually defined IP-address, have a look at this issue https://github.com/docker/docker/issues/6743#issuecomment-99066339
Thanks, that's an interesting issue. Unfortunately from what I can see, because of the way Consul does leader election and maintains cluster state, it is not possible to stop and restart a docker-compose cluster with a Consul server as one of the containers because it gets very confused when it doesn't find its IP as expected, and it keeps trying to locate the old IP address in order to join a cluster that doesn't exist. I'll keep digging and see if there's anything that can be done but right now it's not looking good. Thanks for the reply.
This is not something that is supported by docker engine, so wont be supported by compose
It seems docker 1.10 now supports --ip. it might worth to have some way to map deterministic address with the the container postfix number assigned by scale service=num
Can the --ip option supported by docker-compose for passing to containers? That would be great.
Please open a new issue for supporting the ip container option , it's not supported yet
Done. #3064