How to Install and Use Docker on Alpine Linux

Docker is a popular open-source containerization platform that makes it possible for developers to build, ship, and deploy their applications inside isolated environments called containers. Unlike virtual machines, containers are lightweight environments that ship with all the libraries, dependencies, and files required by an application to run.

In this guide, we will demonstrate how to install Docker on Alpine Linux.

Installing Docker on Alpine Linux

To start off, refresh or update the local package repositories using the following apk command.

# apk update

To install docker and docker-compose from the Alpine Linux repositories, execute the command:

# apk add docker docker-compose

This installs docker and docker-compose alongside other additional packages, libraries, and dependencies.

Install Docker in Alpine Linux
Install Docker in Alpine Linux

So far, Docker is already installed. However, it does not start automatically. Therefore, enable the Docker daemon to start on boot time.

# rc-update add docker
# service docker start

To confirm the version of Docker installed, run the command:

# docker version

The output provides a wealth of information such as Docker, API and Go versions, and OS architecture just to mention a few.

Here is a summary of the output.

Check Docker Version in Alpine Linux
Check Docker Version in Alpine Linux

Testing Docker on Alpine Linux

To start using Docker, you need to add the regular user to the docker group as shown.

# addgroup tecmint docker

To test if Docker is actually working, we will pull a hello-world image from the Docker hub and run a container from the image.

To do this, run the command:

$ docker run hello-world

The command displays the Hello from Docker! message and provides you with the steps it took to print the message to the terminal.

Run Docker in Alpine Linux
Run Docker in Alpine Linux

Now let us try something more ambitious. We will pull a Debian image from the Docker hub as follows:

$ docker pull debian

This pulls the latest Debian image.

Docker Pull Debian Image
Docker Pull Debian Image

To confirm the images residing on your system run:

$ docker images

The output tells us that we have two images – the hello-world and the debian images.

List Docker Images
List Docker Images

To create a container from the Debian image and access the shell, we will run the command:

$ docker run -it debian /bin/bash

<
From here, you run commands on the shell just as you would on an actual Debian system. For example, you can check the version of Debian as follows:

# cat /etc/os-release
Check Debian Version
Check Debian Version

To exit the container, run the command:

# exit

To view currently running containers, execute:

$ docker ps

To list all containers including those which have exited after running run:

$ docker ps -a
List Docker Containers
List Docker Containers

This wraps up our guide for today. In this guide, you have learned how to install Docker on Alpine Linux.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.