LXD - Linux OS containers
LXD containers are lightweight virtual machines that provide an environment similar to a virtual machine but with lower overhead. They allow users to run multiple isolated Linux systems (containers) on a single host, leveraging the Linux kernel's capabilities for resource isolation and virtualization. LXD extends LXC (Linux Containers) by providing a more user-friendly interface, advanced management features, and enhanced security.
Step 1 - Launch instance
Create an instance on your Cloud Provider to serve as the host system for the containers
I am using Ubuntu 24.04 as my host operating system and the instance has 4GB ram with 2CPUs.
Step 2 - Update the host system
Step 3 - Install LXD
Follow the prompts on screen
Step 4 - Launch container
I repeated the above process to launch four LXD containers
To list all the running containers:
You can access a container directly with the below command:
This will open a terminal session directly in the running container, where you can then install the require packages and applications in an isolated Linux virtual environment.
I have installed Apache webserver and will use the first container to build and host a static web application.
Since the container does not have a public IP address, as it runs within another host, I can access its services by mapping the container's service port to an open port on the host system. This allows me to use the host's IP address and the assigned port number to access the service in the container.
To access the static web page hosted in the container, I mapped port 81 on the host system to port 80 (the default port for HTTP traffic) on the container and opened port 81 on the host system firewall. Now, I can directly access the static web page from my web browser using http://ipaddress:81
.
See the common LXD commands below:
lxc launch Creates and starts a new container from an image.
lxc init Initializes a new container without starting it.
lxc start Starts an existing container.
lxc stop Stops a running container.
lxc restart Restarts a running container.
lxc delete Deletes a stopped container.
lxc list Lists all containers with their status.
lxc info Shows detailed information about a specific container.
lxc config Manages container configuration options.
lxc exec Executes a command inside a running container.
lxc file Manages files inside containers.
lxc snapshot Takes a snapshot of a container.
lxc restore Restores a container from a snapshot.
lxc copy Copies a container or snapshot to a new container.
lxc network Manages container networks.
LXD containers offer a powerful and efficient solution for running isolated Linux environments. Their lightweight nature, combined with the ability to manage multiple containers effortlessly, makes them ideal for developers, system administrators, and enterprises looking to optimize their infrastructure. With LXD, you gain the flexibility, scalability, and performance needed to handle diverse workloads while maintaining a high level of security and resource efficiency. Embracing LXD containers can significantly enhance your system's capabilities and streamline your operations, making it a valuable addition to any tech toolkit.
Last updated