Docker Community Forums

Share and learn in the Docker community.

Docker Swarm 1.13 Static IP's for Containers?

docker

(Gdock84) #1

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…


(Ajunglsy) #2

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


(Ajunglsy) #3

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


(Linuxrebel) #4

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


(Ajunglsy) #5

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.


(Spencerjang) #6

Has there been any update regarding this issue?


(Stephanwalter) #7

Naything new?

Ist there now a support, or not?