Alpine Linux + Docker with Portainer

I started playing around with containers and Docker about two years ago and I always used Ubuntu as my OS. Recently I discovered Alpine Linux and I fell in love of how light and simple it was. So I decided to write a simple tutorial for beginners on how to install Docker on Alpine Linux and finish by deploying Portainer.

Installing Alpine Linux

I will be installing Alpine Linux in a VM on my Proxmox instance so in my case I will be using the Virtual ISO of Alpine Linux 3.11.3 (please make sure you use the apropriate image for your setup)

After booting up from the ISO the following is the first screen that we will be faced with

Login with root:

root

and then you need to run

setup-alpine

to start the installation process of Alpine Linux into your machine/system.

Once prompted to select my keyboard I selected:

us

and the same for the variant:

us

then you will be asked to choose a hostname for your machine/system. I went with:

alocker

a combination of the work alpine+docker. Trying to keep it “loose” around here.

Alpine was able to detect my NIC as eth0 and I don’t need to do any extra configuration so when prompted which NIC i want to initialize I chose of course:

eth0

Next you will need to choose if you will be doing DHCP or manul configuration of your IP address. I will be choosing DHCP in my case and I will be assigning a static IP address from my pfSense later on but DHCP for now it will be just fine.

dhcp

Next question is if you need to do any manual network configuration which was also a no.

no

After an IP address is assigned then you will be prompted to change the password for root user.

Next will be your proxy. If you do use a proxy this will be the right time to set it, if no the none will do.

none

Then i will be choosing:

chrony

Then you will prompted to choose a mirror from the list. I went with f for to ping the servers and find the fastest one.

f

Then I will be going with openssh for my ssh server.

openssh

And now its time to select and erase our destination drive. My system detected my drive as sda so I will be choosing that drive to use as sys and then when prompted to erase it yes is the answer.

sda
sys
yes

Now we are ready to reboot our system! Alpine Linux is successfully installed. make sure you remember to eject the mounted installation ISO if you still have it mounted.

Installing Docker

So we restarted our machine and now it time to get the ball rolling for Docker. So first things first we will need to add the following community repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/community. We can do that by running the following command:

echo http://dl-cdn.alpinelinux.org/alpine/latest-stable/community >> /etc/apk/repositories

Once that is done now we can run:

apk add docker
apk update

Last step now will be to add docker to start as a service so if we restart our machine then docker will start on boot.

rc-update add docker boot

If you want to install docker-compose as well you can run the following:

apk add py-pip
apk add python-dev libffi-dev openssl-dev gcc libc-dev make
pip install docker-compose

Deploying Portainer

The deployment of Portainer is very very simple and for all starters a GUI to start out with Docker just makes it easier. All you have to do it is run the following two lines of code:

docker volume create portainer_data
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

If everything went according to plan then know you should be able to access your Portainer by opening http://IPAddress:9000 where IP address is the IP address of your Alpine machine of course.

Once you set your login credentials on the next screen you will be chosen to select your Portainer environment and you will select Local.

Boom voila your Docker is ready to be messed with!