Red Green Repeat Adventures of a Spec Driven Junkie

Getting Started in Alpine Linux

My friend, Mahesh, posted an article from anchore that detailed some of the popular Linux distributions used in Docker.

The thing that was really intriguing for me in the article was the image size of the public image size:

Linux Distribution Public Image
Sizes

source

Wow, Alpine Linux is dramatically smaller than almost everything on the list, especially my default distribution: Ubuntu.

This made me think: if I’m including a Vagrantfile to install a whole virtual machine to run my projects, picking a small one will help:

  • download times - smaller distribution, less download, less waiting.
  • setup times - even using the downloaded image, vagrant will make a copy.
  • disk space - smaller is better, especially since I’m basically using the virtual machine as a “deploy appliance”.

So, I jumped into alpine Linux with vagrant.

Getting Vagrant Images

The Vagrant Boxes page lists available Alpine Linux boxes that vagrant can use.

generic/alpine3.6

Initially, I used the generic/alpine3.6 image as it was the most recently updated, but found one main issue: it did not support shared folders in vagrant. I tried to configure it via: config.vm.shared_folders option and reading through the Virtualbox section on the wiki, but there seemed to be something about virtualbox guest additions I could not get working properly. If shared folders are not needed, the generic/alpine3.6 image is fine. (If you know how to get it working, let me know!)

maier/alpine-3.6-x86_64

Currently, 3.6 is the current version of alpine linux and I went with this image maier/alpine-3.6-x86_64. The notes page lists it has support for virtualbox guest additions. So there seems to be something done in this image but not in the generic/alpine3.6 image.

Installing Alpine Linux

I started with this Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "maier/alpine-3.6-x86_64"
end

and ran:

( host )$ vagrant up

Ok, nothing special so far.

Disk Size

Let’s look at the amount of drive space this took:

Alpine Linux Drive Space
Usage

Hmm… not bad, 550MB. Wow, that makes me wonder, how much space does Ubuntu 14.04 (Trusty Tahr) use?

Ubuntu 14.04 Drive Space
Usage

Oh wow… a basic install of Ubuntu Trusty is using 1.47GB, almost three times more than alpine??

Ok, Alpine Linux just got me interested just based on this.

HTOP

Let’s look inside and compare process list through HTOP: sudo htop

Alpine Linux HTOP process
list

Not bad, 21 tasks using 20MB of RAM.

Let’s check what it is on Ubuntu/Trusty:

Ubuntu 14.04 HTOP process
list

Ok, 30 tasks, 40% more than alpine. But wow, look at the memory usage: 118MB. This is 6x more than alpine.

This is enough convincing for me, how do I get started using alpine more?

Well, Alpine linux is a barebones linux. It has only a handful preinstalled items. It uses a different package manager than apt, which I’m comfortable in.

The Emacs Test

As a test, I always like to see how to install emacs on a system.

To install things in apk, alpine’s package manager, the command is: apk add <package>.

( guest ) $ sudo apk add emacs
(1/11) Installing dbus-libs (1.10.14-r0)
(2/11) Installing gmp (6.1.2-r0)
(3/11) Installing nettle (3.3-r0)
(4/11) Installing libffi (3.2.1-r3)
(5/11) Installing libtasn1 (4.10-r2)
(6/11) Installing p11-kit (0.23.2-r1)
(7/11) Installing libunistring (0.9.7-r0)
(8/11) Installing gnutls (3.5.13-r0)
(9/11) Installing libxml2 (2.9.4-r4)
(10/11) Installing emacs-nox@community (25.3-r0)
(11/11) Installing emacs@community (25.3-r0)
Executing busybox-1.26.2-r7.trigger
OK: 769 MiB in 82 packages

Tada~!

With Emacs installed, I have most of the tools to do work on Alpine Linux.

Why Emacs?

I like using emacs as a test for package management. It’s a piece of software that has enough users that almost every system will have it, but default installtion is not guaranteed.

For those curious, yes, vi is on Alpine Linux, although it seems to be version 1.26.2 2017-08-03 13:08:12 GMT.

Package Add ERROR

Originally, on generic/alpine3.6, to install emacs, I tried: sudo apk add emacs and got this response:

( guest ) $ sudo apk add emacs
ERROR: unsatisfiable constraints:
  emacs-nox-25.3-r0:
    masked in: @community
    satisfies: emacs-25.3-r0[emacs-nox]
  emacs-25.3-r0:
    masked in: @community
    satisfies: world[emacs]

It took some poking around and I learned: apk add <package> defaults to repositories without #@# in the name. The generic/alpine3.6 image has a /etc/apk/repositories listing of:

https://dl-3.alpinelinux.org/alpine/v3.6/main
https://mirror.leaseweb.com/alpine/v3.6/main
@community https://dl-3.alpinelinux.org/alpine/v3.6/community
@community https://mirror.leaseweb.com/alpine/v3.6/community
@testing http://nl.alpinelinux.org/alpine/edge/testing
@edge http://nl.alpinelinux.org/alpine/edge/main/

So, to add things from the #community# or #edge# repository, add @community or @edge the package name to match the leading indicator. The maier/alpine-3.6-x86_64 image includes the community repository by default.

Package Listing

To find out what packages are part of alpine linux and in what repository, this page provides a full list with search:

http://pkgs.alpinelinux.org/packages

This page lists emacs support.

Architecture Support

Looking at the Architectures column for the packages, I realize the number of computing architectures supported by Alpine Linux. The architecture wiki page lists six different computing architectures:

  • 2 x86 based (32bit and 64bit)
  • 2 ARM based (32bit and 64bit)
  • 1 PowerPC based (64bit)
  • 1 IBM System Z based (s390x)

Conclusion

This was a quick comparison of resource usage of Alpine Linux in a virtual machine environment using vagrant.

As Alpine Linux has 1/3 of the disk storage requirements, 1/6 the RAM usage, and 40% fewer tasks than Ubuntu 14.04 (Trusty Tahr), I will focus on using Alpine Linux as my default system image for my projects.

Alpine Linux’s package management system, apk, is pretty straight forward, as it can install emacs easily. :-)

With this knowledge, I will start using Alpine Linux in my projects and maybe try it out full time.