compose icon indicating copy to clipboard operation
compose copied to clipboard

Is it possible to setup static IP address for container using Fig?

Open rusllonrails opened this issue 12 years ago • 10 comments

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.

rusllonrails avatar Aug 26 '14 10:08 rusllonrails

@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 avatar Aug 26 '14 10:08 LK4D4

@LK4D4 thanks, will checkout docker links

rusllonrails avatar Aug 26 '14 10:08 rusllonrails

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.

masonoise avatar May 15 '15 23:05 masonoise

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

thaJeztah avatar May 16 '15 00:05 thaJeztah

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.

masonoise avatar May 16 '15 03:05 masonoise

This is not something that is supported by docker engine, so wont be supported by compose

dnephin avatar Sep 01 '15 14:09 dnephin

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

clkao avatar Feb 25 '16 10:02 clkao

Can the --ip option supported by docker-compose for passing to containers? That would be great.

daniel-smith-kaazing avatar Mar 02 '16 19:03 daniel-smith-kaazing

Please open a new issue for supporting the ip container option , it's not supported yet

dnephin avatar Mar 02 '16 20:03 dnephin

Done. #3064

daniel-smith-kaazing avatar Mar 02 '16 20:03 daniel-smith-kaazing