Skip to main content

Command Palette

Search for a command to run...

Containerization for Cybersecurity: A Beginner’s Guide

Updated
7 min read
Containerization for Cybersecurity: A Beginner’s Guide

Learn how to use containers to improve your security posture.

Ever heard the dreaded phrase, “It works on my machine!”? Yeah, we all have. As cybersecurity professionals, we know that inconsistent environments can be a nightmare. That’s where containerization swoops in to save the day!

This post is your containerization crash course. We’ll break down the basics, explore popular tools, and even get our hands dirty with a security-focused project. Consider this your starting point for understanding how containers can make your cybersecurity life a whole lot easier.

What Exactly is Containerization?

Think of it like this: you’ve built a super cool robot (your application). To transport it safely, you wouldn’t just toss it in the back of a truck. You’d pack it carefully in a crate with everything it needs to function: batteries, tools, spare parts, the works. That’s containerization!

In tech terms, a container is a lightweight package that bundles your application with all its dependencies: code, runtime, libraries, and settings. This guarantees your app runs smoothly no matter where it lands, just like your robot arrives ready to roll, no matter the journey.

Why Should Cybersecurity Folks Care?

Containerization is a game-changer for security:

  • Consistency: Say goodbye to “it works on my machine” woes. Containers ensure consistent behavior across different environments, reducing those pesky configuration discrepancies that attackers love to exploit.
  • Isolation: Containers provide a degree of isolation, limiting the damage from security breaches. Think of it as damage control — if one container gets compromised, it’s less likely to spread to others.
  • Efficiency: Containers are leaner than virtual machines, making them easier to deploy and manage. This means you can spin up secure test environments or deploy security tools quickly and efficiently.

Your Container Toolkit: Docker, Podman, Kubernetes

These are your go-to tools for containerization:

  • Docker: The most popular container platform, known for its user-friendly interface and massive community.
  • Podman: A rising star with a strong focus on security and running containers without root privileges.
  • Kubernetes: The orchestrator for managing and scaling containers across clusters of machines. Think of it as the conductor of your container orchestra.

Cybersecurity: Benefits and Challenges

Containers offer some sweet security perks:

  • Reduced Attack Surface: Only essential components are included, minimizing potential vulnerabilities.
  • Immutable Infrastructure: Container images are typically immutable, reducing the risk of configuration drift and unauthorized changes.

But, there are challenges too:

  • Shared Kernel: Containers on the same host share the OS kernel, so a kernel vulnerability could affect multiple containers.
  • Image Security: It’s vital to ensure your container images are free of vulnerabilities and malware.

A Quick Note on Architecture

While containers excel at portability, keep in mind that underlying system architectures can sometimes throw a wrench in the works. Different processor architectures (like x86 and ARM) might require specific container images. But don’t worry, we’ll tackle those nuances in future posts!

Hands-On Project: Exploring Containerization

Ready to get your hands dirty? Let’s dive into a project that will give you a real feel for containerization. We’ll start with the basics and then layer in more advanced concepts, allowing you to explore the security benefits and challenges we discussed earlier.

Setting the Stage

Pre-requisites: I am using a virtual machine running Ubuntu 24. You can get a quick one with services like DigitalOcean or your favorite cloud provider and do all of this over SSH.

  1. Choose your platform:

  2. Docker: A popular choice known for its user-friendly interface and extensive documentation.

  3. Podman: A rising star with a focus on security and rootless containers.

2. Installation:

  • Follow the instructions on the official Docker or Podman website for your operating system. (I am going to be using Podman because its easier to install on Ubuntu)

Your First Container

  1. Pulling a sample image:

  2. Open your terminal or command prompt.

  3. Type docker pull hello-world or podman pull hello-world and press Enter.
  4. This downloads a basic container image that simply prints a “Hello from Docker!” message.

2. Running the container:

  • Type docker run hello-world or podman run hello-world and press Enter.
  • You should see the “Hello from Docker!” message, confirming your setup is working.

Building Your Own Container

Now, let’s create a simple web application and package it into a container.

  1. Create a basic web page:

  2. Create a file named index.html with the following content:

<!DOCTYPE html>


My Containerized Web App


Hello from my container!

2. Create a Dockerfile (it will work with Podman):

  • In the same directory as index.html, create a file named Dockerfile (with no extension) and add the following content:

FROM docker.io/nginx:1.16

COPY index.html /usr/share/nginx/html

  • Important: Make sure you’re in the same directory as your Dockerfile and index.html when you run the build command in the next step. This directory is your "build context," and both Docker and Podman need to know where to find your files.

3. Build the container image:

  • In your terminal, navigate to the directory containing the Dockerfile and index.html.
  • Type docker build -t my-web-app . or podman build -t my-web-app . and press Enter.
  • This builds a container image named my-web-app based on the Dockerfile instructions.

4. Run the Container:

  • For Docker: Type docker run -d -p 8080:80 my-web-app and press Enter.
  • For Podman:
  • Enable the Podman socket (this step helps us with a later section): systemctl --user enable --now podman.socket
  • Then run: podman run -d -p 8080:80 my-web-appThis runs your container in detached mode (-d) and maps port 8080 on your host machine to port 80 in the container.

5. Access your web app (using curl):

  • Open your terminal.
  • Type curl http://localhost:8080 and press Enter.
  • You should see the HTML content of your index.html file displayed in the terminal. This confirms that your web application is running correctly within the container. You could also go to a web browser and check, I just didn’t want to leave the terminal and touch my mouse…

Exploring Security Benefits and Challenges

  1. Image Security

Time to put on our security hats! We’ll use a tool called Trivy to scan our container image for vulnerabilities. Trivy is like a security guard for your containers, checking for any known weaknesses that could be exploited by attackers.

2. Traditional Remediation (The Hard Way):

Imagine fixing this on a server without containers. You’d need to:

  • SSH into the server.
  • Update the Nginx package (if available).
  • Manually patch or recompile if no update exists.
  • Restart Nginx.
  • Test to ensure the fix didn’t break other things.
  • Repeat this on every server running this app.

3. Containerized Remediation (The Easy Way)

With containers, it’s a breeze:

  • Update your Dockerfile to use a newer Nginx (newest at the time of this writing):

FROM docker.io/nginx:1.27.2
COPY index.html /usr/share/nginx/html

  • Rebuild the image: docker build -t my-web-app . or podman build -t my-web-app .
  • Get the container ID of the running container: docker ps or podman ps
  • Stop the old container, replacing <container_id> with the ID you got from the previous step: docker stop <container_id> or podman stop <container_id>
  • Run a new container with the updated image: docker run -d -p 8080:80 my-web-app or podman run -d -p 8080:80 my-web-app
  • Rescan with Trivy: trivy image my-web-app. The nginx vulnerabilities should be gone!

Highlighting the Benefits

  • Efficiency: No more server-by-server patching. Just rebuild and redeploy.
  • Consistency: The fix is applied identically across all environments.
  • Rollback: If something goes wrong, redeploy the old image. Easy peasy (lemon squeezy)!

Taking it Further

  • Explore Kubernetes: Deploy your web application to a Kubernetes cluster and explore its orchestration capabilities.
  • Dive deeper into security: Implement security best practices for containerized environments, such as secrets management, least privilege, and image signing.
  • Contribute to the community: Share your containerized projects