How to create a Docker Cluster with Swarm on VMware Photon

How to create a Docker Cluster with Swarm on VMware Photon

Introduction

In this post I would like to share how to create a Docker Cluster with Swarm on the new VMware Project Photon.

Project Photon is an open source Linux container host which is optimized for running on VMware vSphere. It has a very small footprint, is extensible and supports the most common container formats including Docker, Rocket and Garden. You can find more information about Photon at the VMware GitHub site.

Docker Swarm is native clustering for Docker. It allows you create and access to a pool of Docker hosts using the full suite of Docker tools. Because Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.

Without Docker Swarm you are managing each Docker host with a separate CLI session.

 

Docker without Swarm with separate CLI sessions.

 

With Docker Swarm you are able to manage Docker images on a cluster of Docker hosts with one CLI with the standard Docker API.

 

Docker on Photon managed with Swarm.

Photon Configuration

In my Lab Environment I deployed four Photon VM’s. One for managing the Docker Swarm Cluster and three for the cluster nodes.

Installing Photon on new VM’s is very easy and is well documented by VMware, which you can find here.

Again the footprint of Photon is very small (384 MB Memory) and the installation is very quick. You have a running VM in a couple of minutes.

When the VM’s were created I needed to configure a static IP-address since Photon is configured for DHCP by default.

root [ ~ ]# mv /etc/systemd/network/10-dhcp-eth0.network /etc/systemd/network/10-static-eth0.network

My configuration example:

[Match] Name=eth0

[Network]
Address=192.168.20.104/24
Gateway=192.168.20.254</code>
DNS=192.168.20.1</code>
Domains=cloudxtreme.local

Restart the network.

root [ ~ ]# systemctl restart systemd-networkd.service

In this lab I did enable SSH for the root user.

root [ ~ ]# sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
root [ ~ ]# systemctl restart sshd

Docker Swarm Configuration

1. SSH to each node of the cluster. Stop the Docker service and let Docker listen to incoming requests.


root [ ~ ]# systemctl stop docker.service

root [ ~ ]# docker -d -H tcp://0.0.0.0:2375

2. SSH to the Swarm Cluster Management VM and create the new Cluster

root [ ~ ]# docker run --rm swarm create

This command will return a Cluster ID token

e1043c50cb84447d41de500527c04ebd

Docker Swarm Create

3. Now we run an agent for each Cluster Node.

docker run -d swarm join --addr=<node_ip>:2375 token://<cluster_id>

So in my running configuration:

root [ ~ ]# docker run -d swarm join --addr=192.168.20.104:2375 token://e1043c50cb84447d41de500527c0

4. Create the Swarm  Manager in your Management VM.

root [ ~ ]# run docker run -t -P swarm manage

The Swarm Manager starts with a random TCP port. To find out which one run the command

docker ps
root [ ~ ]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                     NAMES
ec38592a23e7        swarm:0.2.0         "/swarm join --addr=   8 minutes ago       Up 8 minutes        2375/tcp                  sharp_sinoussi
7bdea87b7885        swarm:0.2.0         "/swarm manage token   4 days ago          Up 4 days           0.0.0.0:49153->2375/tcp   prickly_yalow
c4ad29b34582        swarm:0.2.0         "/swarm join --addr=   4 days ago          Up 4 days           2375/tcp                  tender_hoover
59352a434d72        swarm:0.2.0         "/swarm join --addr=   4 days ago          Up 4 days           2375/tcp                  grave_poitras
cde216a6aa59        swarm:0.2.0         "/swarm join --addr=   4 days ago          Up 4 days           2375/tcp                  grave_payne<code>

In my configuration it runs on TCP port 49153

Docker ps

5. Command to list the registered agents.

root [  ~ ]# docker run --rm swarm list token://e1043c50cb84447d41de500527c04ebd
192.168.20.103:2375
192.168.20.104:2375
192.168.20.102:2375

6. The Docker Swarm Cluster setup is done. We can use all Docker commands in the cluster.

7. List the status of the Docker Swarm Cluster

root [ ~ ]# docker -H tcp://localhost:49153 info
Containers: 0
Strategy: spread
Filters: affinity, health, constraint, port, dependency
Nodes: 3
electron: 192.168.20.102:2375
└ Containers: 0
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 381.9 MiB
neutron: 192.168.20.103:2375
└ Containers: 0
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 381.9 MiB
proton: 192.168.20.104:2375
└ Containers: 0
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 381.9 MiB

8. Example to run a new Docker container:

root [ ~ ]# docker run -d -it --name wordpress -h wordpress -p 80:80 -p 443:443 appcontainers/wordpress

9. List of the current containers (note the VM hostname in the name of NAMES column of the container):

root [ ~ ]# docker -H tcp://0.0.0.0:49153 ps -a
CONTAINER ID        IMAGE                            COMMAND                CREATED             STATUS                      PORTS                                                              NAMES
c2df483f526a        appcontainers/wordpress:latest   "/bin/sh -c /bin/bas   3 minutes ago       Up 2 minutes                3306/tcp, 192.168.20.104:80->80/tcp, 192.168.20.104:443->443/tcp   proton/wordpress
6b7792daf85d        centos:6                         "/bin/bash"            14 minutes ago      Exited (0) 14 minutes ago                                                                      electron/stoic_fermi
f8c652bfb18b        wordpress:4                      "/entrypoint.sh apac   23 minutes ago      Exited (1) 21 minutes ago                                                                      proton/nostalgic_hawking
7f101ceb9965        appcontainers/wordpress:latest   "/bin/sh -c /bin/bas   30 minutes ago                                                                                                     electron/goofy_colden
34b942afaef8        appcontainers/wordpress:latest   "/bin/sh -c /bin/bas   35 minutes ago

dockerpsswarmcluster

10. List the current status of the Swarm Cluster

root [ ~ ]# docker -H tcp://0.0.0.0:49153 info
Containers: 5
Strategy: spread
Filters: affinity, health, constraint, port, dependency
Nodes: 3
electron: 192.168.20.102:2375
└ Containers: 2
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 381.9 MiB
neutron: 192.168.20.103:2375
└ Containers: 1
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 381.9 MiB
proton: 192.168.20.104:2375
└ Containers: 2
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 381.9 MiB

Docker

 Conclusion

Photon, with it’s small footprint, is lean, fast and perfect for Docker containers on VMware infrastructure. With Photon, Docker and Swarm it is easy to out scale your Docker environment on your VMware infrastructure.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *

Twitter