Background
Docker is a lightweight container technology that is gaining a lot of momentum in the development community. Compared with traditional methods of virtualization, Docker allows rapid prototying, building and shipping an application.
I used Docker to simulate the production environment on my laptop. First step in this process is to have an base image that replicates the virtual or real machines used in production. In this blog, I describe how to create base Docker images from Kickstart files which can be used for creating Openstack/AWS virtual machines or Docker container.
Pre-requisite
- Start a CentOS virtual machine (on VirtualBox, VMWare Fusion or Vagrant). You can download CentOS6.5 virtual machines from [https://github.com/opscode/bento]
- Login to the machine.
- Add the EPEL repository from where we shall install the tools required to create images.
sudo yum install -y http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Creating base image
- Install image creation tools on Centos VM.
sudo yum install -y appliance-tools libguestfs-tools
- Create an image in QCOW2 format appliance-creator can be used to automatically install a virtual machine using the kickstart file.
sudo appliance-creator -c container-65.ks -d -v -t /tmp \ -o /tmp/myimage --name "centos65" --release "6.5" \ --format=qcow2;
- Export from QCOW2 to tar
sudo virt-tar-out -a /tmp/myimage/centos65/centos65-sda.qcow2 / - | gzip --best > centos65.tar.gz
- Import image to docker registry
cat centos65.tar.gz | sudo docker import - imtiaz/centos65:latest
- Optional step: Publish image to docker hub (public image repository for docker images)
sudo docker push imtiaz/centos65
Since posting this article, I found several other options for creating base images. Although Boxgrinder works fine in general, there has been no active development for pas few years. I would recommend using Packer (http://packer.io) or appliance-creator tools (from Redhat) for base image creation.
ReplyDeleteWell written .keep sharing Devops Online Training
ReplyDelete