WittCode💻

Docker Alpine

By

Learn about the benefits of using the Docker Alpine image. We will go over what the Alpine Linux distribution is and why it is so small.

Table of Contents 📖

Docker Alpine

Docker Alpine is a lightweight Linux distribution. One reason Alpine is so lightweight is that it comes with minimal utilities pre-installed. This also makes Alpine more secure as it lowers the attack surface. We can check the size of the Alpine image by spinning up a container and using docker ps.

docker run -it --name my-alpine-c alpine:3.14
docker ps --size
f24a3c3214d3   alpine:3.14       "/bin/sh"                7 seconds ago   Up 6 seconds                                             my-alpine-c           0B (virtual 5.35MB)

Due to Alpine's security and lightweight nature, it is often used as a base image in Docker builds.

INFO: Alpine is built around musl libc and BusyBox. libc is a library that Linux requires to run.

Installing Packages

Even though Alpine comes with a minimal set of utilities, we can install packages with apk, Alpine's package management tool.

apk add --no-cache mysql-client
mysql
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)

Of course, adding packages like this will increase the size of the container.

docker ps --size
CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS                PORTS                              NAMES                 SIZE
f24a3c3214d3   alpine:3.14       "/bin/sh"                7 seconds ago   Up 6 seconds                                             my-alpine-c           0B (virtual 5.35MB)
docker ps --size
CONTAINER ID   IMAGE             COMMAND                  CREATED              STATUS                PORTS                              NAMES                 SIZE
f24a3c3214d3   alpine:3.14       "/bin/sh"                About a minute ago   Up About a minute                                        my-alpine-c           34.6MB (virtual 39.9MB)

Pre-Installed Alpine Images

There are also many Docker images that have a desired package or library pre-installed on the Alpine Linux distribution. For example, Nginx and Node.

docker pull nginx
docker pull nginx:alpine
docker images
REPOSITORY                                TAG                                        IMAGE ID       CREATED         SIZE
nginx                                     alpine                                     70594c812316   3 weeks ago     47MB
nginx                                     latest                                     a9dfdba8b719   3 weeks ago     193MB
docker pull node
docker pull node:alpine
docker images
REPOSITORY                                TAG                                        IMAGE ID       CREATED         SIZE
node                                      alpine                                     3f776ed3998d   44 hours ago    152MB
node                                      latest                                     8018d9bdf679   44 hours ago    1.11GB
Docker Alpine