Playing with docker on Fedora 20

To get familiar with docker I took a look to see what it would take to build and/or run various containers, it was surprisingly easy (all commands below were run as root)

Install/start and enable docker

yum install docker-io
systemctl start docker
systemctl enable docker

The instructions below go through creating 2 docker images (the first is based on busybox and the second is fedora), if you would just like to use one that has already been created you can download it from the docker registry and then just start using it.

docker pull fedora
docker images
docker run -t -i fedora:20 /bin/bash

If all you want to do is run this pre-built fedora image you can stop here.

On the other hand if you would like to get your hands dirty and create your own images then …

Build a root file system for the container

yum --installroot=/root/bbroot --releasever=20 install busybox

Remove cached data

cd /root/bbroot/
rm -rf ./var/cache/yum/* ./var/lib/yum/yumdb/* ./var/lib/yum/history/* ./var/log/yum.log

Build symlinks to busybox for the utilities it provides

mkdir bin
for linkname in $(./sbin/busybox --list) ; do ln -s /sbin/busybox bin/$linkname ; done

Import it into docker as a new image

tar -czf - . | docker import - busybox:v1

And your done, you can now start your new container with the docker run command

docker images
docker run -t -i --name busybox busybox:v1 /bin/sh

Of course if you want more Fedora goodness in your image(the busybox example for most people wouldn’t be very useful beyond a lightweight (<2MB) test) you can install yum and coreutils and skip the symlink step

yum --installroot=/root/fedroot --releasever=20 install yum fedora-release-20 coreutils
cd /root/fedroot/
rm -rf ./var/cache/yum/* ./var/lib/yum/yumdb/* ./var/lib/yum/history/* ./var/log/yum.log
tar -czf - . | docker import - myfedora:v1
docker run -t -i myfedora:v1 /bin/sh

2 Comments

  1. Joe Pesco says:

    Looking at your posting and working through the two fine examples caused me to ask myself the age old question of “What good is this to me now?” Allow me provide a humble example for further exploration.

    I used the “mattdm/fedora” container available at index.docker.io because I’ve already got a web server container with httpd & Mariadb that is going strong. Starting from the basic container install node.js and set up the basic web server example for node.js. It is only a few lines of code. Hint: listen at port 80 in the node.js example! The Bash script that runs the Docker container looks like:

    #!/bin/bash
    docker run -p 8085:80 -i -t mattdm/fedora:nodejs.research.latest /bin/bash

    This configuration allows us to point our browsers at localhost:8085 after getting the node server example script started and seeing the results of our labors in our browsers. A pretty slick/cool and useful thing to do!