compose icon indicating copy to clipboard operation
compose copied to clipboard

Define static IP address for container

Open fredrikaverpil opened this issue 10 years ago • 15 comments

It would be useful to be able to define a static IP address for a container within the docker-compose.yml.

I see that docker run --ip xxx.xxx.xxx.xxx is now available in docker 1.10.0-rc2. More details in the merged pull request: https://github.com/docker/docker/pull/19001

Example:

docker network create --driver=bridge --subnet=192.168.0.0/24 --gateway=192.168.0.1 mynet
docker run --ip=192.168.0.10 --net=mynet -ti some_image

fredrikaverpil avatar Feb 02 '16 10:02 fredrikaverpil

+1

m4h3 avatar Feb 08 '16 09:02 m4h3

+1

this is very useful if you need setup extra iptable

bitraft avatar Feb 12 '16 06:02 bitraft

+1

wangstoney avatar Feb 17 '16 10:02 wangstoney

+1

kujiy avatar Feb 17 '16 10:02 kujiy

+2!

mort1k avatar Feb 19 '16 21:02 mort1k

+1

viktorsmari avatar Feb 22 '16 13:02 viktorsmari

Can you give us a snippet of a YAML with this new feature (static IP) please ?. Thanks in advance.

marouim avatar Feb 25 '16 15:02 marouim

Sure - few caveats: this PR requires docker-py >= 1.8.0: https://github.com/docker/docker-py/pull/936 and Docker Engine >= 1.10.x (API: 1.22). This PR hasn't been looked at yet by the compose owners, so it may change, here is the YAML I've been using for testing:

version: '2'

services:
  ubuntu:
    image: ubuntu
    networks:
      test:
        ipv4_address: 172.16.238.10
        ipv6_address: 2001:3984:3989::10
    command: sleep 1000

networks:
  test:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "true"
      com.docker.network.bridge.enable_ip_masquerade: "false"
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
        gateway: 172.16.238.1
      - subnet: 2001:3984:3989::/64
        gateway: 2001:3984:3989::1

mdaue avatar Feb 27 '16 11:02 mdaue

Thank you! That is exactly what I needed. I think this feature is still in the pull request process, so I guess I'm not getting it with a "git clone" right ? Do you have any idea when this is gone a be merged ?

Thanks again.

marouim avatar Feb 28 '16 12:02 marouim

No idea; I think the docker-py pre-requisite will be merged with 1.8.0. You won't get it with a git clone, unless you pull from these feature branches: (docker-py first, then: compose). This is really not sustainable and not at all recommended for production use as it gets out of sync with master, probably be best to wait for this feature to be merged.

mdaue avatar Feb 28 '16 13:02 mdaue

+1 Commenting here so I'll be advised when it's merged.

daniel-smith-kaazing avatar Mar 03 '16 00:03 daniel-smith-kaazing

Using docker-compose 1.7.0 and docker 1.11.0 creating a network with ipv6 support as in the example here and the new compose documents does not work.

  com.docker.network.enable_ipv6: "true"

seems to have no effect, when inspecting the network it shows "EnableIPv6": false. Creating the network with

  docker network create --ipv6 ...

the network supports IPv6 and shows as "EnableIPv6": true

gaertner-mike avatar Apr 28 '16 14:04 gaertner-mike

ipv4 works well for me.

Dan Smith

Senior Support Engineer | Phone: 650.960.8155 | Mobile: 408.835.1167 [email protected] [email protected]

------------------------------------------------------------

KAAZING >|< When Real-time Matters Kaazing.com http://www.kaazing.com/ | Download http://kaazing.com/download.html | Blog http://blog.kaazing.com/ | Twitter https://twitter.com/kaazing http://kaazing.com http://kaazing.com/about-us/careers/

On Thu, Apr 28, 2016 at 7:20 AM, gaertner-mike [email protected] wrote:

Using docker-compose 1.7.0 and docker 1.11.0 creating a network with ipv6 support as in the example here and the new compose documents does not work.

com.docker.network.enable_ipv6: "true"

seems to have no effect, when inspecting the network it shows "EnableIPv6": false. Creating the network with

docker network create --ipv6 ...

the network supports IPv6 and shows as "EnableIPv6": true

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/docker/compose/issues/2804#issuecomment-215439970

daniel-smith-kaazing avatar Apr 28 '16 15:04 daniel-smith-kaazing

yes IPv4 works well, but I am not looking forward to support IPv4 NAT for docker in production deployment.

gaertner-mike avatar Apr 28 '16 16:04 gaertner-mike

same issue as @gaertner-mike, com.docker.network.enable_ipv6: "true" has no effect, created network has the right IPv6 configuration, except "EnableIPv6": false, so it's not usable (docker 1.11.1, docker-compose 1.7.0).

alo-is avatar May 07 '16 23:05 alo-is