How to install docker on Alpine Linux VM
15th March 2019 3 By George WouIntroduction
Alpine linux is a lighweight linux distro, making it small, fast and ideal for VM’s when server resources are limited. Especially when talking about running docker containers, a VM is the only way to go since LXC containers are not supported and its hacky to make docker run inside an LXC.
The Docker containers can be administered through the command line or by using a GUI tool.The two most lightweight administration tools are:
- Cockpit, it can run only in systemd distros so it is not an option for Alpine.
- Portainer, comes as a docker container, ideal for Alpine.
Following are the steps required to configure an Alpine system and install Docker.
Create Alpine VM on Proxmox
Download the latest .iso from Virtual category in https://alpinelinux.org/downloads/ .
Upload it to Proxmox VE from gui and create VM.
- OS -> Other OS types
- CD/DVD -> Use disk image (iso)
- Hard Disk -> Bus/Device IDE 0 , Storage local-lvm, Cache Default (no cache)
- CPU -> Type Default(kvm64)
- Memory -> Auto allocate and input the desired range
- Network -> Bridged mode , Model VirtIO (paravirtualized)
Again these are suggested defaults and depend on the machine and the network plan we have in mind.
Initial Setup
Still in Proxmox GUI , go to the new VM’s console, login as root and type:
setup-alpine
and answer the questions of the wizard,including changing the root password.Alpine setup is possibly the easiest linux setup.Defaults are fine except in the disk creation.After selecting disk (sda) and purpose (sys), at least for this simple use case, type (y) in the warning:erase the above disk and continue ? question.
Alpine will prepare the portion of the hard disk allocated to our VM and will ask to reboot.
After rebooting the vm, from the proxmox console of the Alpine VM create a group and a user so we can ssh to the vm remotely from the terminal of our choice and not be bound to the builtin console of the proxmox GUI anymore:
addgroup -g 150 docker
adduser -G docker dockeras
cat /etc/passwd
We use docker group name on purpose because it will be needed later.
Now add the user in sudoers file to be able to execute all commands:
apk add sudo
visudo
add anywhere this line:
dockeras ALL=(ALL) ALL
Now press ESC and :wq to save and exit the editor. :q! to exit without saving.
Note:If for any reason we need to ssh as root,from proxmox GUI console:
vi /etc/ssh/sshd_config
and replace #permitrootlogin no with permitrootlogin yes .Save and exit the editor.Then restart ssh service:
service sshd restart
Now we can leave the proxmox console and ssh to the server from another machine:
ssh [email protected]
Install qemu-guest-agent [optional]
poweroff
sudo apk add qemu-guest-agent
nano /etc/init.d/qemu-guest-agent
command_args="-m ${GA_METHOD:-virtio-serial} -p ${GA_PATH:-/dev/vport1p1} -l /var/log/qemu-ga.log -d"
rc-update add qemu-guest-agent boot
Install Docker Engine
We need to add the community repository in alpine that contains docker:
vi /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
Now update the repositories, check that docker is present in apk and install:
sudo apk update
apk policy docker
sudo apk add docker
make docker always start on Alpine boot:
sudo rc-update add docker boot
sudo service docker start
service docker status
docker run --rm hello-world
NFht7gXEfkAMCoGqc%3D: dial tcp: lookup production.cloudflare.docker.com on 192.168.1.100:53: read udp 192.168.1.158:48125->192.168.1.100:53: i/o timeout.
setup-dns
Conclusion
In this article we described the proccess of creating an Alpine VM, OS preparation , creation of a group and a user to operate our dockers, installation of the Docker daemon and a solution for a common error .
For docker administration consult the follow up article How to install Sonarr Radarr and Jackett with Docker.
Reference:
https://wiki.alpinelinux.org/wiki/Tutorials_and_Howtos
Part 2:How to install Sonarr Radarr and Jackett with Docker
Part 3:How to install Sonarr Radarr and Jackett with Docker-Compose
3 Comments
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Hello,
you’ve done a great how-to.
I have a problem with the installation of qemu guest agent.
I have a quite similar server configuration than you.
I applied all the commands that you’ve described here.
But proxmox tells that the agent is still not working.
May i ask you if you could give me some tips or clues on what i could do next. please?
Thank you very much in advance for any tips.
Best regards
1)If you followed the steps make sure you shutdown and start the VM, dont just reboot it.
2)On /dev directory you might have a different file like vport1p2, use that instead.
3)These steps are only for Alpine, no need to do this for e.g Debian.Also do apk update && apk upgrade , by now the devs of Alpine might have fixed this problem.
If getting error for missing qemu-guest-agent:
$ sudo apk add qemu-guest-agent
ERROR: unsatisfiable constraints:
qemu-guest-agent (missing):
required by: world[qemu-guest-agent]
Uncomment community repository before trying to install qemu guest agent by modifying /etc/apk/repositories
Info Link: https://wiki.alpinelinux.org/wiki/Enable_Community_Repository