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…