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
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:
Then press Insert button on the keyboard and add the following line in the file.
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.
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
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
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.
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
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:
And added the following nameservers:
nameserver 188.8.131.52 nameserver 184.108.40.206
2. After installing the Alpine, the network was unreachable, thus we edited:
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.