Streamline Your Linux Development with Containers: A Comprehensive Guide

Are you looking to enhance your Linux development experience? Discover how Linux containers can revolutionize your workflow by providing a tailored development environment in this detailed guide.

Selecting the Right Container Platform

When it comes to establishing a development environment on Linux, various containerization platforms are at your disposal. This guide will introduce you to popular options such as Docker, Podman, and LXC.

Choosing the Optimal Container Platform

For those newly diving into container technology, Docker is a fantastic first choice due to its robust support and user-friendly interface. However, Podman and LXC present their own distinct benefits. Here’s a brief comparison:

  1. Docker:
    Renowned as the leading container tool, Docker is celebrated for its simplicity and extensive community support, making it an excellent choice for beginners.

  2. Podman:
    This container engine specializes in running and managing OCI containers on Linux, featuring a "rootless" mode that allows operations without root access—broadening its application.

  3. LXC:
    Lightweight and efficient, LXC provides an environment similar to virtual machines while sustaining a traditional Linux feel, catering to a minimalist approach.

Installing Your Chosen Container Platform

Once you’ve selected your preferred container engine—be it Docker, Podman, or LXC—the next step is installation. Launch a terminal on your Linux system and follow the instructions corresponding to your platform choice.

Docker Installation

Begin by installing Docker on your Linux distribution using the appropriate package manager.

For Ubuntu/Debian:

sudo apt update
sudo apt upgrade
sudo apt-get install ca-certificates curl gnupg lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get install docker-ce docker-ce-cli containerd.io

For Arch Linux/Manjaro:

sudo pacman -Syu
sudo pacman -S docker
sudo systemctl enable --now docker

For Fedora:

sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io

For OpenSUSE:

sudo zypper addrepo https://download.docker.com/linux/opensuse/docker-ce.repo
sudo zypper install docker-ce
sudo systemctl enable --now docker

Podman Installation

To install Podman, utilize these commands on your specific Linux distribution.

For Ubuntu/Debian:

sudo apt install podman

For Arch Linux/Manjaro:

sudo pacman -S podman

For Fedora:

sudo dnf install -y podman

For OpenSUSE:

sudo zypper ar -f obs://devel:kubic:libcontainers:stable podman
sudo zypper in podman

LXC Installation

Follow these steps to set up LXC on your machine.

For Ubuntu/Debian:

sudo apt update
sudo apt upgrade
sudo apt install lxc lxc-templates bridge-utils
sudo systemctl enable --now lxc.service

For Arch Linux/Manjaro:

sudo pacman -Syu
sudo pacman -S lxc
sudo systemctl enable --now lxc.service

For Fedora:

sudo dnf install lxc lxc-templates lxc-extra
sudo systemctl enable --now lxc.service

For OpenSUSE:

sudo zypper install lxc
sudo systemctl enable --now lxc.service

Creating Your Container Development Environment

With your preferred container platform set up, it’s time to establish your development environment. This example will showcase how to build a Rust development setup within your container.

Using Docker

To set up a Rust development environment within Docker, begin by creating a Dockerfile using the following command:

touch Dockerfile

Next, open and edit the Dockerfile in the Nano text editor:

nano -w Dockerfile

Insert the following code to define the environment:

FROM ubuntu:latest
RUN apt-get update && apt-get install -y curl build-essential
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

Save your changes by pressing Ctrl + O, and exit with Ctrl + X. Now, build your container:

sudo docker build -t ubuntu-rust .

Once the build is complete, you can run your container:

sudo docker run -it ubuntu-rust

Using Podman

To establish a Rust development environment in Podman, begin by pulling the latest Ubuntu image:

podman pull ubuntu:latest

Next, create a "Podmanfile":

touch Podmanfile

Edit it in the Nano text editor:

nano -w Podmanfile

Add the following instructions:

FROM ubuntu:latest
RUN apt-get update && apt-get install -y curl build-essential
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

Build the container:

podman build -t ubuntu-rust .

And run it:

podman run -it ubuntu-rust

Using LXC

To create an LXC Rust development environment, initiate the process with:

lxc-create -n rustcontainer -t download -- -d ubuntu -r focal -a amd64

Start the container using:

lxc-start -n rustcontainer

Attach to your container:

lxc-attach -n rustcontainer

Within the container, set up Rust with the following commands:

sudo apt update
sudo apt install -y curl build-essential
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env

Your LXC Rust developer environment is now ready for use.


With this guide, you’re equipped to enhance your Linux development experience through containerization, streamlining your workflow to make coding more efficient and organized.

By

Tech journalist and digital trends analyst, Alex Reynolds has a passion for emerging technologies, AI, and cybersecurity. With years of experience in the industry, he delivers in-depth insights and engaging articles for tech enthusiasts and professionals alike.