There’s been a lot of buzz lately around the Go programming language. A lot of cool tools have been written using it. One in particular, which has a lot of buzz too: Docker.
Like many others, I’m really interested in Docker, because it has the potential to help me resolve a recurring issue: facilitating software deployments as much as possible.
Most deployments issues have been solved, for me at least, by using a CM tool like Chef. Problem is, sometimes, you need to roll back a deployment, and even if you use a CM, that’s
gonna be tricky.
With Docker, you simply have to replace a contrainer, and you are good to go.
So as I explore that new technology, I plan on posting my findings and experience with it here.
In this first installment, I will explore building a RHEL/Centos Docker base image.
What is Docker?
Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack
clusters, public clouds and more.
Requirements
a RHEL/CentOS VM
a kernel supporting AUFS
Docker
febootstrap (available in the EPEL repository)
IP Forwarding enabled (otherwise, networking in containers won’t work)
Getting our environment ready
I’ve written a Chef cookbook (use >= 0.1.6) that takes care of setting up a Docker-ready server. I recommend using that to get up and running quickly. Otherwise, make
sure you meet the above requirements before moving on.
Building the image
We’ll be using febootstrap to create a RHEL/CentOS image in a fakeroot. It mimics the behavior of debootstrap. Very useful to create images for LXC/OpenVZ.
NOTE: Make sure you run febootstrap as
root. Otherwise, you gonna walk into a world of pain with permissions in your container.
Now that we have our image in our fakeroot, we need to import it into Docker.
[iyunv@banshee ~]# cd centos/
[iyunv@banshee centos]# tar -c . | docker import - centos
5df8a8c8477a
Our newly created image is now available and ready for use.
[iyunv@banshee centos]# docker images
REPOSITORY TAG ID CREATED SIZE
centos latest 5df8a8c8477a 38 seconds ago 316.8 MB (virtual 316.8 MB)
Testing our new image
Let’s see if it works.
[iyunv@banshee centos]# docker run centos /bin/ping google.com -c 1
PING google.com (24.200.237.123) 56(84) bytes of data.
64 bytes from 24.200.237.123: icmp_seq=1 ttl=60 time=10.7 ms
--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 13ms
rtt min/avg/max/mdev = 10.742/10.742/10.742/0.000 ms