Create a Proxmox LXC container Template

Create a Proxmox LXC container Template

Spread the love

This morning at work I have been migrating our docker compose containers that currently run on an Ubuntu 22.04 Server VM onto individual Proxmox LXC containers running Ubuntu 22.04 so I thought that I would document it here so that I have a record of what I did and pass on the information as the containers seem to work way better running on LXC containers and they use way less resources than the Ubuntu 22.04 VM.

While I was playing around with the LXC containers I discovered that if you use a template you can speed up container roll out and it will also make it really easy to use Ansible to automate the roll out of new and existing containers going forwards which is a massive plus for me 🙂

Download the LXC Template

Before we can create the template we first need to have an Ubuntu 22.04 Proxmox LXC image downloaded on your server to boot from. To do this log into the Proxmox gui and click on the Proxmox server name:

Create a Proxmox LXC container Template

Click on Shell to open up the server command line:

Create a Proxmox LXC container Template

We are going to use the pveam command line tool to fetch our image but first we need to update pveam to the latest version by running the following command:

pveam update

This will show the following when run successfully:

Create a Proxmox LXC container Template

Next run the following command to see all the images that are available to download:

pveam available

This will show a long list of images that can be downloaded:

Create a Proxmox LXC container Template

Scroll up and find the Ubuntu images and copy the name of the 22.04 image:

Create a Proxmox LXC container Template

Next run the following command to download the ubuntu image:

pveam download local ubuntu-22.04-standard_22.04-1_amd64.tar.zst

Wait for the image to download. It will not take very long as it is very small (129.82mb):

Create a Proxmox LXC container Template

This will have copied the new image to /var/lib/vz/template/cache/ and it will now show up in the Local disk, CT Templates in the gui:

Create a Proxmox LXC container Template

Create LXC VM

Before we can create a LXC container template we first need to create an LXC container using the Ubuntu 22.04 image that we have just downloaded using pveam.

To create the LXC Container click on the Create CT Button at the top right of the screen:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 25

Fill in the desired CT ID:, name of the LXC Container, Type in desired password in the 2 password Fields and if you want to use an ssh key to connect to the VM add that too:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 26

Click Next to save the changes and move to the next tab:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 27

Click on the arrow and select the Ubuntu 22.04 image:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 28

Click next to move to the disks tab:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 29

Change the disk size if needed or leave as default 8GB is that is enough and click Next:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 30

Click next if you are ok with giving the container the default 1 cpu core, or change to the required number and click next again:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 31

Click Next to accept the default 512mb ram or change to the desired memory amount and click next:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 32

Change the IPv4 setting from Static to DHCP so that it will get an ip address automatically when it boots as will the cloned LXC container when they boot then click Next:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 33

Add the desired dns server ip addresses to the fields and then click next:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 34

Check that all the settings are correct and then click next to create the container:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 35

Proxmox will now create the container:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 36

Close the window when finished and the new container will now be in the container/vm list:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 37

Click on the new Container name and select Console and click Start now to start the Container:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 38

The container will now start (Almost immediately! Yah Containers!):

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 39

Log into the container with the user of root and the password setup during configuration:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 40

Configure the new container with whatever you need to install

One advntage of using LXC Containers over VM’s is that there is no need for the Proxmox Guest agent to be installed so that is one less thing that needs to be installed! Here is what I install for my base template:

Run the following command to update apt:

apt update

Once that has finished run the following command to update Ubuntu:

apt upgrade -y

I then install vim as it is my preferred text editor by running:

apt install vim

Type y and press enter to install vim:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 41

Wait for vim to be installed.

Next I allow the root user to ssh using a password by running:

vim /etc/ssh/sshd_config

Find the line that contains PermitRootLogin prohibit-password:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 42

Change the line to PermitRootLogin yes

Create a Proxmox LXC container Template

Save the file.

As most of my LXC containers will be used to run docker compose containers I install docker and docker compose using the instructions from THIS post.

That is all my Template has installed but feel free to add anything else you need on a standard container and then power off the VM. The easiest way to do this is to click the Shutdown button at the top of the console:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 43

Click Yes to confirm shutdown:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 44

The container will now power off.

Convert the LXC container to a template

To convert you newly configured LXC container to a template to use to quickly create new containers from right click on the LXC container’s name in the left hand menu of the GUI:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 45

Select Convert to template:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 46

Click Yes to convert the LXC Container to a template:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 47

The image to the left of the name will now change to indicate that it is now a template:

Create a Proxmox LXC container Template
Create a Proxmox LXC container Template 48

That is the end of the Ubuntu 22.04 LXC Container setup tutorial. You now have a ready to use template.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top