chriszg 发表于 2015-10-13 07:19:07

building a centos docker base image

  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.


# 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:00
febootstrap/primary_db                                                                                     | 4.4 MB   00:03
febootstrap-updates                                                                                        | 3.4 kB   00:00
febootstrap-updates/primary_db                                                                           | 4.4 MB   00:02
Setting up Install Process
Resolving Dependencies


  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.


# cd centos/
# tar -c . | docker import - centos
5df8a8c8477a

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


# 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.


# 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



# docker run -t -i centos /bin/bash
bash-4.1# uname -r
3.10.5-3.el6.x86_64
bash-4.1# hostname
d393248f8119

  That’s it.
  In the next installment, I will explain how to customize our new base image to run a website using Nginx.
页: [1]
查看完整版本: building a centos docker base image