DevTech101

DevTech101

Managing Docker Swarm

The below Docker swarm how to is part of build highly available private docker registry.

To configure Docker Swarm you will need minimum 3 nodes, below I will use the names/ip’s listed in part 1.

To initialize the Docker Swarm cluster, just run the below on the first node coreos1.

# Use if the server has multiple interfaces
# docker swarm init --advertise-addr 10.0.2.11
docker swarm init

Next, run the below, on the two other nodes (coreos2 and coreos3).
Replace the token with your Docker Swarm token.

docker swarm join \
--token SWMTKN-1-58uz09763fitew2samqtowgse75dc9px7gxk2qokf5uc5mu9f2-20ve9z6nj34o202ybf9tiqk3j \
10.0.2.11:2377

For fail-over to work properly, in recent versions, run the below on node2 and node3, this is needed to allow the other two node become manger in case the first node fails.

docker node promote coreos2
docker node promote coreos3

Now, lets verify the cluster functionality.

docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
8c6qmlmo9uym11obvyo3irgib     coreos1             Ready               Active              Reachable
ilmw12fa1kdyzsi5nrmfpi8bk     coreos3             Ready               Active              Reachable
ykafu6ww70nbklvrvgpc5qoiy *   coreos2             Ready               Active              Leader

Next, create a Docker Swarm network.

docker network create \
--driver overlay \
--subnet 10.20.1.0/24 \
--opt encrypted \
services

Next, create Docker Swarm service.

docker service create \
--replicas 2 \
--name nginx \
--network services \
--publish 80:80 \
nginx

Now, verify the cluster network and service.

docker service ls
docker service ps nginx

docker network ls
Docker helpful examples

A Docker Swarm busybox example.

docker service create \
--name busybox \
--network services \
busybox \
sleep 3000

Verify the ps busybox Docker Swarm.

docker service ps busybox

Running the busybox as part of Docker Swarm.

docker exec -it busybox.1.4czfvm7771qy8lmbiz2bv4nbwdocker /bin/sh
docker service inspect --pretty nginx

Scale the busybox service as part of Docker Swarm.

docker service scale nginx=3
docker service ps nginx
Destroying the Docker Swarm cluster

Single node to leave the cluster.

docker node demote coreos2
docker node demote coreos3

Last node to leave the cluster – on coreos1.

docker swarm leave --force

You might also like
Other articles related to Docker Kubernetes / micro-services.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: