Docker Swarm in CentOS 7, learn by example
Installation
1. Download CentOS 7 Minimal install ISO Image and install it on 5 machines (Could be VMs as well)
2. Set static IP address on all nodes
2. Set static IP address on all nodes
$cat /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.107.140
NETMASK=255.255.250.0
GATEWAY=192.168.104.1
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens160
UUID=012345678-2163-4bf8-850d-123456781234
DEVICE=ens160
ONBOOT=yes3. $ service network restart
4. $ sysctl -w net.ipv4.ip_forward=1
Install Docker Service on all machines
5. $ curl -sSL https://get.docker.com/ | sh6. sudo systemctl stop docker
Configure instance
7. Create the directories and configuration files as$ mkdir -p /etc/systemd/system/docker.service.d/
$ vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://myProxy.com:80"
$ sudo systemctl daemon-reload
$ sudo systemctl show --property Environment docker
Environment="HTTP_PROXY=http://myProxy.com:80"
vi /etc/systemd/system/docker.service.d/docker.conf8. Check and validate instance configurations
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
$ sudo systemctl restart docker
$ sudo docker login
$ sudo docker run hello-world
Machine Configurations and roles
IP Fucntion Description 192.168.107.140 Node 01 Running containers and storing images 192.168.107.141 Node 02 Running containers and storing images 192.168.104.236 Node 03 Running containers and storing images 192.168.107.142 Consul 01 & Management 01 Consul: Discovery Background, Management: manage and access the Docker Swarm 192.168.104.235 Node 04 & Management 02 Running containers and storing images, Management: manage and access the Docker Swarm
Consul Instance Configuration
To keep things simple, we run a single consul daemon on the same host as one of the Swarm managers.Use SSH to connect to the consul0 instance.$ ifconfigFrom the output, copy the eth0 IP address from inet addr.Paste the launch command into the command line:sysctl -w net.ipv4.ip_forward=1$ sudo docker run -d -p 8500:8500 --name=consul progrium/consul -server -bootstrapEnter docker ps.From the output, verify that a consul container is running.
Management Instances Configuration
ssh to manager 01
$ sysctl -w net.ipv4.ip_forward=1
docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise 192.168.107.142:4000 consul://192.168.107.142:8500
ssh to manager 02
$ ifconfig
Start the secondary Swarm manager using following command.
sysctl -w net.ipv4.ip_forward=1
$ sudo docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise 10.160.104.235:4000 consul://192.168.107.142:8500
Nodes Instances Configuration
Connect to node 1, node 2 and node 3 in turn and join them to the cluster.
Start a Swarm container each using the following syntax:
sysctl -w net.ipv4.ip_forward=1
sudo docker run -d swarm join --advertise=192.168.107.140:2375 consul://192.168.107.142:8500
sysctl -w net.ipv4.ip_forward=1
sudo docker run -d swarm join --advertise=192.168.107.141:2375 consul://192.168.107.142:8500
sysctl -w net.ipv4.ip_forward=1
sudo docker run -d swarm join --advertise=192.168.104.236:2375 consul://192.168.107.142:8500
Test Configuration
Connect to Management 1Check Swarm information using following syntax:$ sudo docker -H :4000 info
Containers: 22
Running: 6
Paused: 0
Stopped: 16
Images: 15
Server Version: swarm/1.2.5
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 4
dockerHost: 192.168.107.140:2375
└ ID: RF2E:R27P:XFWC:2B36:DOYJ:RHRU:EIEF:NCLN:3YBY:HZ7A:RYKW:KMAT
└ Status: Healthy
└ Containers: 8 (1 Running, 0 Paused, 7 Stopped)
└ Reserved CPUs: 0 / 8
└ Reserved Memory: 0 B / 516.5 GiB
└ Labels: kernelversion=3.10.0-327.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
└ UpdatedAt: 2016-10-27T05:07:28Z
└ ServerVersion: 1.12.2
localhost.localdomain: 192.168.104.236:2375
└ ID: SP4D:OVOH:K5SF:BWNL:MRGD:EDZU:HJD6:Y5UX:DUR6:N7YD:LW5R:MTVN
└ Status: Healthy
└ Containers: 2 (1 Running, 0 Paused, 1 Stopped)
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 1.887 GiB
└ Labels: kernelversion=3.10.0-327.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
└ UpdatedAt: 2016-10-27T05:07:16Z
└ ServerVersion: 1.12.2
localhost.localdomain: 192.168.107.141:2375
└ ID: FGHH:CCLK:BTJD:PA27:6NMX:K6RQ:3ZPC:SVV4:HWML:HJYQ:MKJY:DHF4
└ Status: Healthy
└ Containers: 8 (2 Running, 0 Paused, 6 Stopped)
└ Reserved CPUs: 0 / 8
└ Reserved Memory: 0 B / 31.83 GiB
└ Labels: kernelversion=3.10.0-327.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
└ UpdatedAt: 2016-10-27T05:07:44Z
└ ServerVersion: 1.12.2
localhost.localdomain: 192.168.107.142:2375
└ ID: BM4X:XGZR:6YA5:WPVA:OKOB:ON76:3KSL:GMGI:ROPV:D2TB:VWCC:BJKB
└ Status: Healthy
└ Containers: 4 (2 Running, 0 Paused, 2 Stopped)
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 1.887 GiB
└ Labels: kernelversion=3.10.0-327.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
└ UpdatedAt: 2016-10-27T05:07:30Z
└ ServerVersion: 1.12.2
Plugins:
Volume:
Network:
Swarm:
NodeID:
Is Manager: false
Node Address:
Security Options:
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: linux
Architecture: amd64
CPUs: 19
Total Memory: 552.1 GiB
Name: 95d3e2eac529
Docker Root Dir:
Debug Mode (client): false
Debug Mode (server): false
WARNING: No kernel memory limit support