How to install Docker CE on Alpine Linux

For Docker containers, Alpine Linux is an optimum choice because of lightweight, low RAM consumption and optimization. However, yet Ubuntu is the best. 

Alpine Linux is a free and open-source Linux operating system for routers, firewalls, VPNs, VoIP computers, servers, virtual machines and containers. It has proactive security features that prevent security holes in the software from being exploited. The small, lightweight Linux distribution based on musl libc and busybox.

Steps to install Docker on Alpine Linux


I am not going to talk much on Docker here because if you are reading this tutorial then you would already know what it is. Well, in short Docker is a containerized Virtualization platform that allows running different virtual machines in the form of isolated containers. The best thing about it, lightweight and easy to handle; one can simply pull existing Linux or apps images to setup a container from hub.docker.com.

Step 1: Download and Setup Alpine Linux


If you already have a working Alpine Linux then simply move to the next step and if not then go to this link and download one. Alpine Linux is available in multiple forms such as Standard, Extended with some extra packages, Net-install, Optimized Virtual ISO image, for Xen with built-in support for Xen Hypervisor and in Minimal root filesystem for containers. You can download one as per your choice, however, here we are using Alpine Linux Extended version 3.11.

After downloading boot your PC or VirtualBox with it and run the command setup-alpine to follow the installation steps.

Step 2: Command to install Docker on Alpine


Run the following single command to fetch Docker packages for its installation on Alpine.

apk add docker

Install docker on Alpine linux-min

Step 3: Apk add fails with unsatisfiable constraints error 


Incase after executing the above command you get an error “apk add fails with unsatisfiable constraints” then we have to add the following repository to Alpine.

Edit the Alpine repository file:

vi /etc/apk/repositories

Then press Insert button on the keyboard and add the following line in the file.

http://dl-cdn.alpinelinux.org/alpine/latest-stable/community

To save and exit first press Esc and then type:wq after that press the Enter button.

Once you are done, run the package update command to let the system know about the updated repository, so that it can index the same.

apk update

Step 4: Add Docker service to the system boot level


To make sure the service of Docker gets automatically started every time along with the boot of the Alpine, we have to add it to our system services.

rc-update add docker boot

Now, we can start the Docker service

service docker start

Add docker service to boot level-min

Step 5: Install Docker Compose 


Users those also want the Docker Compose on Alpine, first, they have to install pip.

apk add py-pip

Few dev dependencies

apk add python-dev libffi-dev openssl-dev gcc libc-dev make

Finally, run command to install docker-compose

pip install docker-compose

Install Docker compose on ALpine-min

Step 6: Isolate containers with a user namespace


adduser -SDHs /sbin/nologin dockremap
addgroup -S dockremap
echo dockremap:$(cat /etc/passwd|grep dockremap|cut -d: -f3):65536 >> /etc/subuid
echo dockremap:$(cat /etc/passwd|grep dockremap|cut -d: -f4):65536 >> /etc/subgid

Step 7: Now, check your install Docker


Use below command to check information of installed Docker version.

docker info

Step 8 Pull Docker image on Alpine


To know everything is working fine, let’s pull up a hello-world image

docker pull hello-world

To run the image:

docker run -t hello-world

pulling docker image on Alpine

Additional: Errors we encountered while setting it up


1: error response from daemon https //registry-1.docker.io/v2/ time out

We got the above error because in the resolv.conf of Alpine the nameservers were not configured appropriately, thus we edited it:

vi /etc/resolv.conf

And added the following nameservers:

nameserver 8.8.8.8
nameserver 8.8.4.4

2. After installing the Alpine, the network was unreachable, thus we edited:

vi /etc/network/interfaces

And added the following:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

In this way, we can use this lightweight Alpine Linux for Docker running containerized virtual machines.

3 thoughts on “How to install Docker CE on Alpine Linux”

  1. Newer versions of Alpine have docker-compose in the repo
    ‘docker-compose’ is in ‘Community’ repository since Alpine Linux >= 3.10.
    to install docker-compose

    apk add docker-compose

    Reply
  2. Thanks for this great guide, works great with Windows 10 + VBOX 6.1 + Alpine-virt-3.13.5 & Docker 20.10.3. Only problem was with docker-compose but thx @Rajiv comment I could install without problem from repo.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.