Build Debian Docker Image from Scratch

docker

 

 

 

 

 

 

Now that we have practiced some basic operations with Docker, let’s create, import and start an image. This article covers how to build a Debian docker image from scratch and use it in docker.

We’ll be using the famous debootstrap tool which installs a Debian base system into a subdirectory of another, already installed system.

Build Wheezy

First install debootstrap

$ sudo apt-get install debootstrap

Then prepare the root directory

$ mkdir -p /vdisks/chroot/wheezy

Finally build a Wheezy system

$ sudo debootstrap wheezy /vdisks/chroot/wheezy http://ftp.us.debian.org/debian

At this point you have a small environment which you can chroot into and modify it the way you like

$ sudo chroot /vdisks/chroot/wheezy /bin/bash

You will drop to a bash shell in the newly created system, I won’t do any further changes to this system except modifying the banner

# echo "Debian 7 Docker image" > /etc/motd
# exit

Import Docker Image

Now let’s import this new system into docker:

$ sudo tar -C wheezy/ -c . | docker import - aossama/wheezy
cec2131b98fdfd41d83437509fea930a949f7cd074b66c36a0a6def8e26b5d02

If the import goes well, you will see the ID of the newly imported image

First check the images list:

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
aossama/wheezy latest cec2131b98fd 2 minutes ago 218.6 MB

And start the new image

$ docker run --rm --name=wheezy aossama/wheezy cat /etc/motd
Debian 7 Docker image

And voilĂ , you just built a new docker image, imported it, and ready to dockerize it.

Comments

  1. says

    Hi,

    I personally prefer wordpress as it is straight to the point for building blogs. I am not familiar with BlogEngine or B2evolution, but I use Drupal to build full featured websites.

    I am using WordPress and the theme is WinterSong Pro.

Leave a Reply

Your email address will not be published. Required fields are marked *