Skip to content

Instantly share code, notes, and snippets.

Created December 4, 2018 20:43
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simple docker swarm setup on Centos 7

Install Docker Swarm on Centos 7

Basic Installation

Install required packages

yum install yum-utils lvm2 device-mapper-persistent-data

Add Docker-Repository

yum-config-manager --add-repo

Install Docker-CE

yum install docker-ce

Add regular user to docker group (allows user to exec docker commands without sudo)

usermod -aG docker user

Enable service for autostart and start docker

systemctl enable docker && systemctl start docker

Configure firewall for Docker Swarm

firewall-cmd --permanent --add-port=2376/tcp
firewall-cmd --permanent --add-port=2377/tcp
firewall-cmd --permanent --add-port=7946/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=7946/udp
firewall-cmd --permanent --add-port=4789/udp

Restart Firewall and Docker

systemctl restart firewalld
systemctl restart docker


Init the swarm on the manager

docker swarm init --advertise-addr <MANAGER-IP>

Show master or worker tokens

docker swarm join-token worker
docker swarm join-token manager


Join swarm

docker swarm join --token <TOKEN> <MANAGER-IP>:2377

Start Service

Start simple docker swarm service

docker service create -p 80:80 --name webservice --replicas 2 httpd

Show status

docker service ls

Check logs from all swarms nodes

docker service logs webservice

Scale service

docker service scale webservice=3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment