Linux 119: Using Containers with Podman and Docker
Containers have revolutionized how applications are built, shipped, and run. They allow you to package applications with their dependencies, ensuring consistency across environments. In this article, we'll explore how to use Docker and Podman—two popular containerization tools on Linux.
1. What Are Containers?
A container is a lightweight, isolated environment that includes everything an application needs to run: code, libraries, and system tools—without the overhead of a full virtual machine.
Key benefits:
- Consistent deployments
- Lightweight and fast
- Easy to scale and replicate
2. Docker vs Podman
Feature | Docker | Podman |
---|---|---|
Daemon-based | Yes | No (daemonless) |
Rootless mode | Experimental/stable | Fully supported |
Dockerfile | Supported | Supported |
Compatible CLI | Docker CLI | Docker-compatible CLI |
Podman is often preferred on systems with strict security needs due to its daemonless and rootless nature.
3. Installing Docker
On Ubuntu/Debian
On RHEL/CentOS
Add your user to the docker
group:
4. Installing Podman
On Ubuntu/Debian
On RHEL/CentOS/Fedora
Verify installation:
5. Basic Container Usage
Run a Container
Run a Web Server
List Running Containers
Stop a Container
6. Building Your Own Container Image
Create a file named Dockerfile
:
Build the image:
Run it:
7. Managing Images and Containers
List Images
Remove an Image
Remove a Container
8. Using Volumes for Persistent Storage
This mounts a local directory (/mydata
) inside the container.
9. Rootless Containers with Podman
One of Podman’s major features is the ability to run containers without root privileges:
Everything runs under your user’s permissions, reducing risk.
10. Conclusion
Containers with Docker and Podman allow you to package, test, and deploy applications more efficiently. Whether you're running a single container or orchestrating many, understanding the basics of containerization is essential for modern Linux administration.
Next Steps:
- Learn about container orchestration tools like Kubernetes
- Explore Docker Compose or Podman pods for multi-container setups
- Practice building and running your own containerized applications
Coming next: Linux 120: Setting Up a Linux Web Server with Apache and Nginx