building a centos docker base image

来源:互联网 发布:php soapheader详解 编辑:程序博客网 时间:2024/06/09 13:23

http://failshell.io/docker/building-a-centos-docker-base-image/


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.

[root@banshee ~]# febootstrap -i iputils -i vim-minimal -i iproute -i bash -i coreutils -i yum centos centos http://centos.mirror.iweb.ca/6.4/os/x86_64/ -u http://centos.mirror.iweb.ca/6.4/updates/x86_64/febootstrap                                                                                                | 3.7 kB     00:00febootstrap/primary_db                                                                                     | 4.4 MB     00:03febootstrap-updates                                                                                        | 3.4 kB     00:00febootstrap-updates/primary_db                                                                             | 4.4 MB     00:02Setting up Install ProcessResolving Dependencies[snip]

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.

[root@banshee ~]# cd centos/[root@banshee centos]# tar -c . | docker import - centos5df8a8c8477a

Our newly created image is now available and ready for use.

[root@banshee centos]# docker imagesREPOSITORY          TAG                 ID                  CREATED             SIZEcentos              latest              5df8a8c8477a        38 seconds ago      316.8 MB (virtual 316.8 MB)

Testing our new image

Let’s see if it works.

[root@banshee centos]# docker run centos /bin/ping google.com -c 1PING 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 13msrtt min/avg/max/mdev = 10.742/10.742/10.742/0.000 ms
[root@banshee centos]# docker run -t -i centos /bin/bashbash-4.1# uname -r3.10.5-3.el6.x86_64bash-4.1# hostnamed393248f8119

That’s it.

In the next installment, I will explain how to customize our new base image to run a website using Nginx.



0 0