Using fleetctl to run clustered Docker services
After I’ve started my CoreOS cluster, I demonstrate how to run a sample service on it. In this case a Tomcat 8 Docker container controlled by fleet.
I created a Dockerfile
, which creates a custom container based on the official Tomcat 8 image. Additionally it adds the official sample application provided on apache.org.
1 | FROM tomcat:8-jre8 |
To make this Dockerfile available to all workers in my cluster, I uploaded it to etcd. The path is completely free to choose.
1 | $ etcdctl set /units/tomcat8/Dockerfile < ./Dockerfile |
Now I could create a service file for fleet. The instance notation (@
) and specifiers (%p, %i
) allow to start as many instances as I like, all from one single service file. For details on that review man 5 systemd.service
and man 5 systemd.units
. I also specified role=worker
in the X-Fleet section, to let fleet automatically choose a suitable instance in my cluster.
1 | [Unit] |
Last not least, I registered the service in fleet and started some instances.
1 | $ fleetctl submit tomcat8@.service |
Cheers,
visit