Docker Swarm 1.13 Static IP's for Containers?

Hi All,

I am trying to get static IP’s in my docker swarm containers using the Overlay network but I am falling short.

Can someone please guide me?

Below are my steps. Thanks in advance.

Step 1: Created the external network using Overlay

  docker network create -d overlay \
  --subnet=172.16.231.0/24 \
  --gateway=172.16.231.1 \ 
  --aux-address="elasticsearch=172.16.231.12" --aux-address="logstash=172.16.231.13" --aux-address="kibana=172.16.231.14" \
  elk_default


docker network ls | grep  elk_default  
xxmbj03pdydk        elk_default               overlay             swarm


[root@dockman01 docker-elk]# docker network inspect elk_default
[
    {
        "Name": "elk_default",
        "Id": "xxmbj03pdydk5c4uo1op4ri8c",
        "Created": "0001-01-01T00:00:00Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.16.231.0/24",
                    "Gateway": "172.16.231.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Containers": null,
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4099"
        },
        "Labels": null
    }
]

Step 2: The docker-stack.yml file which says to use the external network elk_default

version: '3'

services:
  elasticsearch:
    image: elasticsearch:latest
    hostname: elasticsearch
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xms1g -Xmx1g"
    networks:
      default:
         ipv4_address: 172.16.231.12
    extra_hosts:
      - "kibana:172.16.231.14"
      - "logstash:172.16.231.13"
  logstash:
    hostname: logstash
    image: logstash:latest
    command: -f /etc/logstash/conf.d/
    volumes:
      - /docker/volumes/docker-elk/logstash/config:/etc/logstash/conf.d
    ports:
      - "5001:5000"
    networks:
      default:
         ipv4_address: 172.16.231.13
    extra_hosts:
      - "kibana:172.16.231.14"
      - "elasticsearch:172.16.231.12"
    depends_on:
      - elasticsearch
  kibana:
    hostname: kibana
    image: kibana:latest
    networks:
      default:
         ipv4_address: 172.16.231.14
    extra_hosts:
      - "logstash:172.16.231.13"
      - "elasticsearch:172.16.231.12"
    volumes:
      - /docker/volumes/docker-elk/kibana/config/:/etc/kibana/
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch

networks:
  default:
    external:
      name: elk_default

Step 3: launch it into the docker swarm

docker stack deploy --compose-file=docker-stack.yml elk
Creating service elk_elasticsearch
Creating service elk_logstash
Creating service elk_kibana

Step 4. Proof that the containers are using the network I created as in Point 1.

docker inspect elk_elasticsearch

 "Networks": [
                {
                    "Target": "xxmbj03pdydk5c4uo1op4ri8c",
                    "Aliases": [
                        "kibana"

"NetworkID": "xxmbj03pdydk5c4uo1op4ri8c",
                    "Addr": "172.16.231.2/24"
                }
						
						
						
						
docker inspect elk_logstash

 "Networks": [
                {
                    "Target": "xxmbj03pdydk5c4uo1op4ri8c",
                    "Aliases": [
                        "logstash"
						
  "NetworkID": "xxmbj03pdydk5c4uo1op4ri8c",
                    "Addr": "172.16.231.4/24"						

docker inspect elk_kibana

 "Networks": [
        {
            "Target": "xxmbj03pdydk5c4uo1op4ri8c",
            "Aliases": [
                "logstash"

 "NetworkID": "xxmbj03pdydk5c4uo1op4ri8c",
                "Addr": "172.16.231.6/24"

Why are these random IP’s given out, and why are the containers not using, the assigned IP’s I gave from the docker-stack.yml file?

Thanks for your time…

2 Likes

Hi gdock84, hi all!

When deploying my yml definition to a Docker Swarm Mode (1.13.1) cluster, I am facing a very similar issue. Comparing my setup with the setup gdock84 describes, there are only two real differences:

  • instead of Kibana, Elastic Search and Logstash, I’d like to run Consul. So it is a differenct docker image, but I try to assign static IPs to my consul containers, too.
  • The overlay network I use is defined within the same yml file (“docker-compose-stack.yml”) I use for the consul containers. But this should not be the point, as that is the way it is meant to be. And the file itself works, meaning:
  • The network is being created.
  • The volumes are being created.
  • All consul containers are created, get their particular volume assigned and start up properly.
  • They even get an IP from the defined address range assigned.

The only thing is, that this IP (from the defined range) is random, not the one I set in the yml file.
No, finally, here is my yml definition:

version: "3"

services:

  px-consul-dsm01:
    image: consul:0.7.5
    command: [agent, -server, -bootstrap-expect=3, -advertise=10.0.11.2]
    networks:
      px-consul-net:
        ipv4_address: 10.0.11.2
    volumes:
      - consul-px-tst:/consul/data
    deploy:
      placement:
        constraints: [node.hostname == t-azeurn-dsm01]

  px-consul-dsm02:
    image: consul:0.7.5
    command: [agent, -server, -bootstrap-expect=3, -advertise=10.0.11.3]
    networks:
      px-consul-net:
        ipv4_address: 10.0.11.3
    volumes:
      - consul-px-tst:/consul/data
    deploy:
      placement:
        constraints: [node.hostname == t-azeurn-dsm02]

  px-consul-dsm03:
    image: consul:0.7.5
    command: [agent, -server, -bootstrap-expect=3, -advertise=10.0.11.4]
    networks:
      px-consul-net:
        ipv4_address: 10.0.11.4
    volumes:
      - consul-px-tst:/consul/data
    deploy:
      placement:
        constraints: [node.hostname == t-azeurn-dsm03]

networks:
  px-consul-net:
  driver: overlay
  ipam:
    driver: default
    config:
      - subnet: 10.0.11.0/24

volumes:
  consul-px-tst:

Any idea, why docker is just ignoring my “ipv4_address:” statements?

Feedback is highly appreciated! Thank you very much!
aj

1 Like

Isn’t there anyone who can add something to this topic?
Should I open a bug?
Best regards
aj

Has anyone come up with a solution to this? It still ignores the setting as noted above.

Static DHCP addresses for containers accessing an overlay network are officially not supported for the time being, as I’ve been told here.
I hope, that docker will provide a solution for this very soon.

Has there been any update regarding this issue?

Naything new?

Ist there now a support, or not?

Hi [gdock84],

I can not help you about Static IP for containers (in swarm mode), but I may make you clear about “the assigned IP’s I gave from the docker-stack.yml file”.

As your docker-stack.yml file, you do not declare the “endpoint mode” (vips or dnsrr). So, default endpoint mode will be used, “vips” mode. In this mode, each service is assigned a vip (virtual IP). And “the assigned IP’s I gave from the docker-stack.yml file” that you mean is the VIP (virtual IP) for the service (kibana, elaticsearch, …). And when using this mode (routing mesh), there is no guarantee about which Docker node services client requests.

Further info about endpoint mode, vip, routing mesh: Overlay network driver | Docker Docs

any update? I hope to allocate a fixed VIP for a container in a docker swarm

Still unavailable: https://github.com/moby/moby/issues/25303 (search for --ip)

Docker swarm services still lack many of plain docker’s (as in docker-compose, docker run) low level features.

are there any workarounds on this?

any update? this is a big limitation in case you need a static IP address

I pasted a link to the current state of supported service features on Github.

After all Docker is maintained by an open source community. May I suggest to either be patient, find a volunter willing to implement it or implement it yourself?

Sorry I completely miss the link you posted.
May I know what the “question mark” means ?

I would assume: unclear/uncertain

Unless it’s not checked (=implemented) or in progress, there is not much hope that a feature will see the daylight anytime soon.

For time beeing, there is no way arround Kuberentes if you need multi host deployments and full control of your containers.

Is there a link to the status of this?

You might be interested in this more flexible Docker Swarm alternative: https://overnode.org/ . You can see it as multi-host docker compose without Swarm, but it is a bit more than this. It has got a great set of features. It also supports static IP addresses. (Disclaimer: I am an author of the project)