Skip to content

Instantly share code, notes, and snippets.

@christofluethi
Created December 4, 2018 20:43
Show Gist options
  • Save christofluethi/358e8072881485df651d568358bc97c9 to your computer and use it in GitHub Desktop.
Save christofluethi/358e8072881485df651d568358bc97c9 to your computer and use it in GitHub Desktop.
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 https://download.docker.com/linux/centos/docker-ce.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

Manager

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

Worker

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