Proxmox is a Virtual Environment manager GUI that sits on top of KVM. It is a custom Debian Linux installation which has features specifically designed for VM’s and LXC Containers. The fact that it is open source makes it a great alternative to VMWare for development and home use. In later posts I will cover creating Linux and Windows VM’s as well as clone templates (a very handy feature to save storage).
Docker is an open platform for developing, shipping, and running container applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. Additionally there is a huge user base which means you can leverage container applications that others have build to speed up implementation. In fact this website is running as a docker application.
First it may be beneficial to go over what a VM and a container are and how they differ.
Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers. The hypervisor (in my case Proxmox) allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, the application, necessary binaries and libraries – taking up tens of GBs. VMs can also be slow to boot.
Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size), can handle more applications and require fewer VMs and Operating systems.
Pros and Cons
There is a fair bit of discussion on which is better and why. Certainly VM’s require more storage but are probably the most secure because all virtualized components are isolated from the host as well as each other. Additionally it is very easy to install a suite of applications together on a VM that share a same purpose without having to manage each in its own container separately. Storage sharing however that can sometimes pose a problem if you have different applications that need to share the same storage but are located on different virtual machines. Here containers have the advantage in that multiple containers have the ability to access the same presented volumes as if they were part of the individual container. another plus for containers is that they do not need to need to adhere to shared code levels as all the dependencies are already built into the container.
In my case I have a use for both and because you can install Docker in the underlying Proxmox Debian install you can have the best of both worlds. Lastly we will be installing Portainer which is a GUI management tool for Docker containers. I find I use this less the more familliar I become with the docker environment but when starting out it is a real time saver!
Lets get Started
So lets start by getting Proxmox installed. First you will need to download the ISO or create a bootable USB with the media on it. This is beyond the scope of this guide but there are several others out there. Once you are ready to boot your media follow the install guide on their website. Once installed you can open a terminal session and we can update the server and install Docker.
First update your install sources to use the free version, make sure your /etc/apt/sources.list looks like the following
# /etc/apt/sources.list
deb http://ftp.debian.org/debian buster main contrib
# PVE pve-no-subscription repository provided by proxmox.com,
# NOT recommended for production use
deb http://download.proxmox.com/debian/pve buster pve-no-subscription
# security updates
deb http://security.debian.org buster/updates main contrib
deb [arch=amd64] https://download.docker.com/linux/debian buster stable
Next we will remove the PVE subscription reminder. Find the line /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js that says ‘No valid subscription’. Change the line above it from ‘Ext.Msg.show({‘ to ‘void({‘ as seen below. Note the line number may be different depending on your version.
void({ //Ext.Msg.show({
title: gettext('No valid subscription'),
icon: Ext.Msg.WARNING,
message: Proxmox.Utils.getNoSubKeyHtml(data.url),
buttons: Ext.Msg.OK,
callback: function(btn) {
if (btn !== 'ok') {
return;
}
orig_cmd();
}
});
} else {
orig_cmd();
}
Lastly update the service
systemctl restart pveproxy.service
Now we will create a location for Docker to run so we are not running from the root system. The first mount point is where docker will run from and the second mount point will be used for any filesystem docker volumes I choose to create.
zfs create -o mountpoint=/var/lib/docker rpool/docker
zfs create -o mountpoint=/docker rpool/docker/app
Lets install Docker
apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
apt update
apt install docker-ce docker-ce-cli containerd.io
We can do a couple of quick tests to ensure docker is installed.
docker --version
Docker version 19.03.13, build 4484c46d9d
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:e7c70bb24b462baa86c102610182e3efcb12a04854e8c582838d92970a09f323
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Congratulations! You can now run docker images on Proxmox pve. But lets take it 1 step further. Rather that remembering all the command line configurations for images many folks like to leverage a tool called docker-compose to create a flat file that contains all the configuration you want in a “.yml” file the file can be used to build and remove images more simply.
Lets install docker-compose. Since I am using a debian system I can simply add it using apt
apt-get install docker-compose
y
docker-compose --version
docker-compose version 1.21.0, build unknown
Ok… so now we have proxmox, docker, docker-compose. We can now install portainer. This will allow easy GUI monitoring of your containers as well as a simple way to log into the container to explore what each look like.
In your home directory create a new directory called Portainer and move into that directory. Then create a file called docker-compose.yml with the following content.
#~home
mkdir portainer
cd portainer
vi docker-compose.yml
version: '2'
services:
portainer:
image: portainer/portainer:latest
command: -H unix:///var/run/docker.sock
restart: always
ports:
- 9000:9000
- 8000:8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
volumes:
portainer_data:
All that is left is to start portainer and log into the gui
#~home/portainer
docker-compose up -d
Now point your browser to http://yourhost:8000 and set your admin password. More information on using and configuring portainer can be found on their website.
In future posts I will cover creating docker networks and joining containers together for specific functions. Thanks for visiting.