How to Set Up Docker Containers in Proxmox

  • Post author:WunderTech
  • Post last modified:March 9, 2024
  • Post category:Proxmox
  • Reading time:14 mins read

In this tutorial, we will look at how to set up Docker Containers in Proxmox. Running Docker containers using Proxmox is an extremely beneficial way to utilize your hypervisor. Especially if you use an LXC container which will drastically reduce system resources.

Why Use an LXC Container for Docker in Proxmox?

Before we look at how to set up Docker Containers in Proxmox, I want to be clear that there are two extremely different ways of accomplishing this. The first is by using an LXC container and the second is by setting up Docker inside of a virtual machine. The main difference between both approaches is how many resources the Proxmox host uses.

When setting up a virtual machine (VM), the resources are specified upfront, meaning that if you specify that the VM should use 4GB of memory, when the VM is started, it will consume 4GB of memory. LXC containers are different in the sense that the memory specified is similar to a limit. Therefore, the system resources will be drastically lower with LXC containers than VMs. There are many other differences between LXC containers and VMs, but that’s the most noticeable difference on a day-to-day basis.

How to Set Up Docker Containers in Proxmox

We will look at how to set up Docker Containers in Proxmox below using an LXC container and a virtual machine (VM).

Utilizing an LXC Container for Docker

The process below will utilize an LXC container and Debian 11 for Docker containers in Proxmox, however, you can really use any distribution that you’d like.

1. Log in to Proxmox, select the storage location where you’d like to store the container template, select CT Templates, then select Templates.

container template screen in proxmox. how to set up docker containers in proxmox

2. Search for Ubuntu, then select ubuntu-22.04 and Download. For the operating system, you can realistically select any Debian-based OS (I used to use Debian), but I’ve found the performance of Ubuntu to be significantly better.

downloading the template.

3. After the template finishes downloading, select Create CT to create a new container.

creating a container in proxmox.

4. Enter a Hostname, then enter the Password you’d like to use. This password will be used to log in to the root user account. After all the settings have been specified, select Next.

NOTE: Make sure the container stays as unprivileged. You do not want to run Docker in a privileged LXC Container for security reasons.

lxc container creation for debian 11.

5. Select the Ubuntu Template, then select Next to proceed.

ubuntu template.

6. Select the Disk Size for this container, then select Next.

lxc container hard drive size.

7. Select the total Cores for the CPU, then select Next.

lxc container cpu entry.

8. Set the total Memory, then select Next.

NOTE: Please keep in mind that this is the limit that this container can use.

lxc container memory selection.

9. Change the Network to use DHCP for IPv4 and IPv6 (unless you want to specify them manually), then select Next until you get to Confirm.

NOTE: We are skipping the DNS section, but you can change these settings if you’d like to use a DNS server different than the Proxmox host.

lxc container network settings.

10. Confirm the settings, then select Finish to create the container!

lxc container confirmation settings.

11. Select the LXC Container we just created, then select Options and Edit the Features.

container options.

12. Enable keyctl, then select OK. You can now start the container!

container keyctl

13. After the container starts, log in with the username root and password set in step four. Run the command below to update the system.

apt update && apt upgrade -y
update container command.

14. After the system is updated, run each of the commands below one by one. These are taken directly from the official Docker documentation and are the prerequisites needed to install the latest version of Docker in Proxmox.

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

After the commands above are run, copy and run the entire command below.

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Finally, update the system.

sudo apt-get update

15. After all of the commands above have been run, run the command below to install Docker!

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
command to install docker.

16. At this point, Docker is fully configured and you’ll be able to create Docker containers. However, if you’d like a GUI, you can install Portainer using the command below.

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

17. If you did install Portainer (and after it’s created), you’ll be able to access Portainer using the IP address of the container and port 9000.

https://[CONTAINER_IP]:9443

Utilizing a Virtual Machine for Docker in Proxmox

If you’d rather install Docker in Proxmox with a Virtual Machine, you can do that as well. This tutorial utilizes Ubuntu Server, but you can use just about any distribution you’d like.

1. Download the ISO image of the operating system you’d like to install, select Create VM, then give the VM a name and select Next.

proxmox virtual machine creation.

2. Select the Storage location, then the ISO Image, and select Next.

proxmox operating system selection.

3. Change the System, Disks, CPU, Memory, and Network. After all of the settings have been configured to your specifications, confirm the settings and create the VM!

proxmox virtual machine creation confirmation.

4. Install the Operating System and then log in after it’s fully installed. When ready, run the command below to install Docker!

NOTE: Please keep in mind that this is a script and while the process is automated, you should trust the origin of the script before you run it. I highly suggest that you review the script before running it. After the script is run, Docker will be installed!

curl -sSL https://get.docker.com/ | sh
proxmox docker curl command.

16. At this point, Docker is fully configured and you’ll be able to create Docker containers. However, if you’d like a GUI, you can install Portainer using the command below.

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

17. If you did install Portainer and after it’s created, you’ll be able to access Portainer using the IP address of the container and port 9000.

https://[CONTAINER_IP]:9443

Conclusion & Final Thoughts

This tutorial looked at how to set up Docker Containers in Proxmox. The biggest question you’ll have to answer is if you want to use an LXC container or virtual machine. The actual setup process (from a Docker perspective) is very similar for each method, however, the Proxmox process of setting up the LXC container or VM is where the steps differ. After using both methods, you should have a functional Docker setup that you can utilize!

Thanks for checking out the tutorial on how to set up Docker Containers in Proxmox. If you have any questions on how to set up Docker Containers in Proxmox, please leave them in the comments!

WunderTech

Frank is an IT professional with 13+ years experience and the creator of WunderTech. He focuses on sharing his experience with others on computer hardware, servers, software, networking, and self-hosted apps. He has a BS in Computer Information Systems and an MBA. Learn more about Frank in his bio.