20 11 2015
Docker is also cool for Ops !
As we know docker is for Build, Ship, Run applications. Usually developers use docker to dev new app and host them with applications like OpenShift.
You can find a lot of article about develop and build application in docker containers. I decided to write a small article on an other aspect of docker that I often use.
Application testing for Ops purpose !
I’m used to do that kind of tests with containers like OpenVz but I recently try to do that with docker.
The last time I use this, it was for the Rabbitmq split brain article. I needed to spawn a rabbitmq cluster, break it, test things and do it again in others versions.
I would like to share with you, how I used docker for this and also a script to simplify the workflow.
What I needed :
- Several VM with network
- Preinstalled packages
- Run startup script to setup the rabbit cluster
- Access to node to do some tests
- Reset all to do it again
My workflow was :
- Get a basic image
- Create a container with it to install required packages
- Save this container as an image
- Write a shared bash script to initiate the rabbitmq cluster
- Start a bunch of containers with my image
- And then execute the init script on each containers
Generate my image from a base image
Start new docker container, in my case a debian one. Install and configure all you will need after in the image. For me it was just setup package like rabbitmq.
When you finish that, exit your docker container and commit your modification to generate a base image (baseimage).
Now you can find this image in your docker images list.
Create my first boot script
All packages I required are present in my base image. Now I write a script myinit_script.sh to initialize and start the app I want to test (rabbitmq cluster for me).
In fact it was just a simple script to apply rabbitmq config and start the cluster.
Start a bunch of containers and do the job
Start to play with docker_setup.py and create all your containers.
The script will create nodes, update /etc/hosts of each containers to be able to use hostname of each containers and mount the /…/foo direcfory from the host in /opt on each containers.
You can access to each containers and ping them. It’s time to test your app :
For the rabbitmq article, my rabbitmq cluster at this state was up and running. It was the moment to create a split brain and try to repair the cluster.
That it, with that you have all informations to test a new app. if you want to reset the stack just call again the script with –create. You also can commit modifications inside a container and then recreate the stack from this new commit.
When you finish to test your app, simply do a cleanup to remove the container stack.
Additionnals informations about the script
- Script link : https://github.com/gaelL/docker-tools
To give you more informations about this script, it don’t do magic stuff. It’s a very small script who use the docker-py module.
Main content of the script is call of docker.client class methods and override some of them to force default values. Also provide commands like creates to call multiple time create with a list of containers.
I let you read the script to know more about. I tried to add a lot of comments.
To discover others feature like share directory go to the readme in github.
Openshift 3 : My node can’t spaw more than 40 pods, why ? Openshift 3 – where is my permanant token ?