Home Alpine Linux How to Install and Use Docker on Alpine Linux

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.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

4 thoughts on “How to Install and Use Docker on Alpine Linux”

    • @Anil,

      Yes, you are right, here are the instructions to add the main and community repositories for the Alpine version you’re using.

      # cat > /etc/apk/repositories << EOF; $(echo)
      
      https://dl-cdn.alpinelinux.org/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/main/
      https://dl-cdn.alpinelinux.org/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/community/
      https://dl-cdn.alpinelinux.org/alpine/edge/testing/
      
      EOF
      

      Don't forget to run the update command after adding the repo.

      # apk update
      
      Reply

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.