Creating a 'base' LXC container to build other containers from

Posted on Fri 04 August 2023 in LXC

بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ

In my previous post about Adding an LXC container with/to virt-manager (Virtual Machine Manager), I mentioned at the end of the article that creating a 'base' container is a good idea for making new containers that have a skeleton or template to build on top of.

This short guide will explain how to setup that base container with some packages to make it useable for software development for Python and JavaScript.

It is worth mentioning here that a good reason for using LXC containers for software development is to isolate all the packages (and the bloat it contains) into its own environment, thus keeping your PC relatively bloat-free.

Create the LXC container

Run this command in any terminal software (like Yakuake, Konsole, Xterm or GNOME Terminal):

sudo lxc-create --template download --name base (interactive, so you choose the options step-by-step)

or this:

sudo lxc-create -n base -t download -- --dist ubuntu --release focal --arch amd64

A container called base based on Ubuntu 22.04 should now exist.

Starting, Connecting and adding a user password

Start the container:

sudo lxc-start -n base

Connect to it:

sudo lxc-attach -n base

The terminal prompt should now say: root@base:/#

Set a root password by typing (and then following the prompts): passwd

Adding base packages

Update the base container:

apt update && apt upgrade

Add some packages to make the container functional:

apt install wget git ssh curl zip nano nodejs npm python3-pip postgresql libpq-dev

The decision on which base packages to add is based on the user.

Cloning 'base' for new project containers

To clone the base container for a new project, run this command at the host level (not within the base container):

sudo lxc-copy -n base -N new-project

where new-project = the name of your new container.

Using Lapce IDE to connect to containers

One of the drawbacks of isolating software development projects in containers is the limited tooling it results in (no code auto-complete, etc.), but a few IDEs (Integrated Development Environments) support connecting to 'remote' development environments via SSH, including Lapce.

In my next article I will explain how to connect Lapce to a development container via SSH.


If you don't know how to use RSS and want email updates on my new content, consider Joining my Newsletter

The original content of this blog is a Waqf solely for the Pleasure of Allah. You are hereby granted full permission to copy, download, distribute, publish and share this content without modification under condition that full attribution is given to this author by creating a link either above or below the content that links back to the original source of the content. For any questions or ambiguity, you are requested to contact me via email for clarification.