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.
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.
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.
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.
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.
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
To exit the container, run the command:
To view currently running containers, execute:
$ docker ps
To list all containers including those which have exited after running run:
$ docker ps -a
This wraps up our guide for today. In this guide, you have learned how to install Docker on Alpine Linux.