Want to simplify your Linux development? Find out how Linux containers can make your work easier by creating a special developer workspace with this in-depth guide.
How to Choose a Container Platform
When setting up a development environment on Linux, there are numerous containerization platforms to consider. This guide will help you get started with Docker, Podman, and LXC.
Deciding on a Container Platform
If you’re new to container technology, starting with Docker might be your best bet due to its widespread support and user-friendly nature. However, Podman and LXC also offer unique advantages. Here’s a quick rundown of each:
Docker:
As the most popular container tool, Docker is known for its ease of use and comprehensive support, making it an ideal choice for beginners.
Podman:
Podman, a container engine for managing and running OCI Containers on Linux, supports “rootless” operation, eliminating the need for root access and opening up more use cases.
LXC:
LXC stands out for its lightweight nature. It offers an experience akin to a lightweight VM, providing a more traditional Linux environment.
Setting Up Your Container Platform
After selecting your preferred container engine (Docker, Podman, or LXC), the next step is installation. Open a terminal window on your Linux system and follow the instructions for your chosen platform.
Docker Installation
Install Docker on Linux using your distribution’s package manager.
How to create your container development environment
With your container platform of choice installed, it is time to create your container development environment. In this example, we’ll focus on setting up a Rust development environment in your container system. However, this is just an example.
Docker
To create a Rust container developer environment in Docker, you need to first create a Dockerfile. You can create a Dockerfile by using the touch command below.
touch Dockerfile
After creating your Dockerfile, open it up for editing in the Nano text editor.
nano -w Dockerfile
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}"
Once you’ve created your Dockerfile, you must save it by pressing Ctrl + O on the keyboard. Then, exit Nano with Ctrl + X. From here, you can build your developer container using the docker build command.
sudo docker build -t ubuntu-rust .
When your container is finished building, you can access it in Docker with the following command.
sudo docker run -it ubuntu-rust
Podman
To create a Rust container developer environment in Podman, start by pulling the latest Ubuntu image. You can do this with the following podman command.
podman pull ubuntu:latest
After pulling the latest Ubuntu image, you’ll need to create a new “Podmanfile.” This file is very similar to a “Dockerfile,” as in it is an instruction manual to build your container. To create a “Podmanfile” use the following touch command.
touch Podmanfile
Open up the “Podmanfile” in the Nano text editor.
nano -w Podmanfile
Paste the following code into the text editor to create your Podman instruction manual.
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}"
You can then build your developer container with the following command below.
podman build -t ubuntu-rust .
Once the developer container is built, access your developer container with:
podman run -it ubuntu-rust
LXC
To create your Rust LXC developer container environment, start by using the lxc-create command.