<< All Posts
How to create an small linux docker container using Alpine Linux


In my latest studies about Docker, I found out a really nice linux distribution called Alpine. This linux is based on BusyBox which makes possible create a nice linux with a really small space on disk.

Most of the official docker images comes with Ubuntu/Debian linux. It ends with at least ~200MB. With Alpine you can reduce it to ~4MB. Lets do an very simple test:



1) Getting Alpine image:

sudo docker pull alpine



2) Listing images. Yes, ~4MB :)

sudo docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              88e169ea8f46        8 weeks ago         3.98 MB



3) Running Alpine and entering on its command line interface:

sudo docker run -it alpine /bin/sh

Also, Alpine linux has a package manager “apk” which some nice softwares on it’s list. You can check the list here: https://pkgs.alpinelinux.org/packages

Let’s do another test. Let’s install Ruby!



4) Updating package list:

apk update

fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
v3.5.1-44-g5aeeee9343 [http://dl-cdn.alpinelinux.org/alpine/v3.5/main]
v3.5.1-44-g5aeeee9343 [http://dl-cdn.alpinelinux.org/alpine/v3.5/community]
OK: 7958 distinct packages available



5) Installing Ruby:

apk add ruby

(1/10) Installing libffi (3.2.1-r2)
(2/10) Installing gdbm (1.12-r0)
(3/10) Installing gmp (6.1.1-r0)
(4/10) Installing ncurses-terminfo-base (6.0-r7)
(5/10) Installing ncurses-terminfo (6.0-r7)
(6/10) Installing ncurses-libs (6.0-r7)
(7/10) Installing readline (6.3.008-r4)
(8/10) Installing yaml (0.1.7-r0)
(9/10) Installing ruby-libs (2.3.3-r0)
(10/10) Installing ruby (2.3.3-r0)
Executing busybox-1.25.1-r0.trigger
OK: 26 MiB in 21 packages



6) Checking the installation:

ruby -v

ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux-musl]



Hope you enjoy!

Rodolfo



Reference:

http://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Add_a_Package

http://containertutorials.com/alpine/get_started.html



<< All Posts