Compose: Define static IP address for container

Created on 2 Feb 2016  Â·  15Comments  Â·  Source: docker/compose

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
areconfig exbeginner kinparity

Most helpful comment

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).

All 15 comments

+1

+1

this is very useful if you need setup extra iptable

+1

+1

+2!

+1

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

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

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.

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.

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

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

ipv4 works well for me.

_Dan Smith_

Senior Support Engineer | Phone: 650.960.8155 | Mobile: 408.835.1167
daniel.[email protected] dorris.[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

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

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).

Was this page helpful?
0 / 5 - 0 ratings