logo

Getting Started with Linux Containers

O

Ohidur Rahman Bappy

MAR 22, 2025

Introduction

Linux containers are a lightweight way to create isolated environments on a Linux system. Using tools like LXD and LXC, you can easily manage these containers. This guide will walk you through the essential steps.

Installing LXD

To get started, you'll need to install LXD using Snap:

sudo snap install lxd

Initializing LXD

Once installed, initialize LXD with the following command:

lxd init

Launching a Container

You can launch different types of containers using various images. Here are some examples:

lxc launch ubuntu:20.04 ubuntu-1
lxc launch images:centos/7 centos-7

Use the following syntax to launch your container:

lxc launch <image-name> <container-name>

Listing Running Containers

To view all running containers, use:

lxc list

Accessing a Container Shell

To run a bash shell inside a container, execute:

lxc exec ubuntu-1 bash

Setting Resource Limits

You can set resource limits such as memory for your containers:

lxc config set ubuntu-1 limits.memory 1000MB

Conclusion

Linux containers provide a powerful way to manage isolated environments. With LXD and LXC, you can easily create and control these environments to suit your development and testing needs.