Tuesday, September 16, 2014

Docker - Create a full Ubuntu Trusty base image using tar

I tried to use the pre-built Ubuntu docker base image from official reposity:

$ sudo docker pull ubuntu
$ sudo docker run -i -t ubuntu:trusty /bin/bash

but the trusty container only has python 3, and I could not install python2.7 or wget. It's such a pain in the ass. So, I decided to build the image myself using the following method:

$ sudo apt-get install debootstrap
$ sudo debootstrap trusty trusty > /dev/null
$ sudo tar -C trusty -c . | sudo docker import - trusty
32f486151f08fa838fd6aa6b9e23b92ebc98e12e8ab36c173f23f71836c003d5
$ sudo docker run trusty cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"

Now I can install python2.7 inside the container running on the new image:

$ sudo docker run -i -t trusty /bin/bash

root@2ff30118feb7:/# apt-get install python2.7