Alpine: Install Package

A minimal Docker image based on Alpine Linux has only 5 MB in size, but a lot of packages common for Linux distributions are not installed by default.

In this short note i will show how to install a package in Alpine container from the command line using the apk (Alpine package manager).

I will also show how to build an Alpine-based Docker image with additionally installed packages.

Cool Tip: Enter a running Docker container and start a bash session! Read More →

Install Package on Alpine

Update the Alpine repository indexes:

# apk update

In case of the following errors, connect to the Docker container as root:

ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

Search for a package to install on Alpine:

# apk search <package>
- or -
# apk search -a <package>
Option Description
-a, --all Show all package versions (instead of the latest only)

Install a package on Alpine Linux from the command line:

# apk add <package>
- example -
# apk add curl

The package on Alpine can also be installed using the --no-cache option:

# apk --no-cache add <package>

Alpine Linux 3.3 and heigher: The --no-cache option has been added in Alpine Linux 3.3. It allows to install packages with an index that is updated and used on-the-fly and not cached locally.

To install a package in Alpine-based Docker image, add the following line to a Dockerfile:

RUN apk --no-cache add <package>

On the older versions of Alpine, a package can be installed as follows:

RUN apk add --update <package> && \
    rm -rf /var/cache/apk/*

Cool Tip: Clean up a Docker host! Remove unused Docker containers! Read More →