Puppet Provisioning with Docker
Puppet Provisioning with Docker
Join the DZone community and get the full member experience.Join For Free
Lately I’ve been messing quite a bit with Docker and my mind is pretty blown about how awesome it is. Remember that feeling you had the first time you launched a vagrant instance and had a virtual machine running with your web application in just a few minutes? That’s the feeling I have again playing with docker… pure awesomeness.
Docker is essentially a wrapper around Linux Containers that makes them usable for mere mortals. With docker I can essentially take my application and all of it’s dependencies, bundle them up into a re-usable image and say “Here, run this!” This has a lot of implications for testing, for repeatability and for system provisioning. I must say it is quite impressive to be able to launch a vagrant box and then run multiple isolated instances of services like rabbitmq or redis inside of it.
It’s easy to try out… if you don’t already run linux you can clone the docker repository and try it out in a vagrant virtual instance. There is also a docker puppet module that you can use to install docker on your own machines if you use puppet. Walking through the examples is a good place to start, once you get a good feel for things you can check out the index for containers that others have shared (there’s some good ones out there, especially the ones published by heroku that emulate their stacks).
For fun, I created an image of a rabbitMQ server. After some trial and error I created the following Dockerfile to build a new image from.
# jamescarr/rabbitmq # # A docker container running rabbitmq 3.1.1 # version 0.1.1 FROM base MAINTAINER James R. Carr <firstname.lastname@example.org> RUN apt-get install -y wget RUN echo "deb http://www.rabbitmq.com/debian/ testing main" >> /etc/apt/sources.list RUN wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc RUN apt-key add rabbitmq-signing-key-public.asc RUN apt-get update # Create dirs that rabbitmq-server wants RUN mkdir -p /var/lib/ /var/log # apt will actually fail because it can't install # upstart scripts for rabbitmq (since it isn't # installed). We don't care, because we won't # be using upstart! RUN apt-get install -y rabbitmq-server || true # let's enable a plugin RUN rabbitmq-plugins enable rabbitmq_management # expose the AMQP port and the management port EXPOSE 5672, 15672 # do this when someone runs the container CMD ["rabbitmq-server"]
Now to generate a new image I just run “docker build < Dockerfile" and wait. Once it is done I am given an image id for the generated image which I can use to tag the image (for those of you following along, "docker tag jamescarr/rabbitmq). Now to run rabbitmq in it’s own isolated environment I can just run “docker run jamescarr/rabbitmq” and see the magic happen. The final piece of the puzzle is you’ll need to run some docker commands to find out what port the ports 5672 and 15672 are exposed as on the host machine, once you have that figured out you should be able to navigate to http://localhost: and be greeted by the rabbitmq management console.
Published at DZone with permission of James Carr , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.