> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Linux as a Virtualization Guest Containers

> Hands-on guide to container management using Podman and Docker compatible CLI commands covering installation, pulling images, running and naming containers, port mapping, stopping and cleaning images.

Hello — this lesson demonstrates practical container management and configuration using Docker-compatible tooling (Podman on RHEL-based systems). We'll cover why containers are useful, how to install and configure Podman, and basic workflows: pulling images, running containers, mapping ports, stopping/removing containers, and cleaning up images.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/qTPiNmqXKGQjbUh5/images/Linux-Professional-Institute-LPIC-1-Exam-101/Linux-Installation-and-Package-Management/Linux-as-a-Virtualization-Guest-Containers/demo-manage-configure-containers-kodekloud.jpg?fit=max&auto=format&n=qTPiNmqXKGQjbUh5&q=85&s=e23ce14a0f00175ac3204e69e1d4bfa9" alt="A dark presentation slide reading &#x22;Demo — Manage and configure containers&#x22; with a small film-camera icon in the center-right and a &#x22;KodeKloud&#x22; logo in the top-right corner." width="1920" height="1080" data-path="images/Linux-Professional-Institute-LPIC-1-Exam-101/Linux-Installation-and-Package-Management/Linux-as-a-Virtualization-Guest-Containers/demo-manage-configure-containers-kodekloud.jpg" />
</Frame>

Why use containers?

* Containers package an application and everything it needs (binaries, libraries, configuration, logs, and data) together. This eliminates fragmented configurations across /etc, /var/lib, /var/log, etc., and makes migration or replication to other hosts predictable and repeatable.
* Example: A MariaDB server inside a container keeps the daemon, configuration files, databases, and logs together. Copy or pull that container on another host and it behaves the same way.

Installing Docker-compatible tooling

* On modern RHEL-based distributions (CentOS Stream, RHEL) Docker packages may not be available; Podman is the recommended replacement. Podman is daemonless, OCI-compliant, and provides Docker-compatible CLI behavior via the podman-docker wrapper.

Install Podman with dnf:

```bash theme={null}
sudo dnf install podman
```

The podman-docker package provides docker CLI compatibility so many existing Docker commands (docker pull, docker run, docker ps, etc.) work unchanged.

<Callout icon="lightbulb" color="#1CB2FE">
  Podman includes a Docker-CLI compatibility wrapper (podman-docker). You can use `docker ...` commands, or call `podman` directly. Podman is daemonless and integrates with systemd and rootless workflows.
</Callout>

Configuring default registries (optional)

* Container tools consult /etc/containers/registries.conf to determine search registries for unqualified image names. To prefer docker.io only, set the unqualified-search-registries array to \["docker.io"].

Example excerpt from /etc/containers/registries.conf:

```toml theme={null}
# An array of host[:port] registries to try when pulling an unqualified image, in order.
unqualified-search-registries = ["docker.io"]
```

* Suppress the informational docker wrapper message by creating the marker file:

```bash theme={null}
sudo touch /etc/containers/no-docker
```

Working with images and containers (nginx walkthrough)
Below is a practical workflow for finding, pulling, running, testing, and cleaning up an nginx container using the Docker-compatible CLI. Replace `docker` with `podman` if you prefer explicit Podman commands.

Search for nginx images in the registry:

```bash theme={null}
docker search nginx
```

Pull the official nginx image (long and short forms both work):

```bash theme={null}
docker pull docker.io/library/nginx
# or
docker pull nginx
```

Example pull output (truncated):

```text theme={null}
Trying to pull docker.io/library/nginx:latest...
Getting image source signatures
Copying blob c4ffe9532b5f done
Copying blob 2215908dc0a2 done
Copying config 12766a6745 done
Writing manifest to image destination
Storing signatures
12766a6745eea133de9fdcd03ff720fa971fdaf2
[aaron@LFCS-CentOS ~]$
```

List images available locally:

```bash theme={null}
docker images
```

Example:

```text theme={null}
REPOSITORY                 TAG       IMAGE ID       CREATED         SIZE
docker.io/library/nginx    latest    12766a6745ee   17 hours ago    146 MB
docker.io/library/nginx    1.20.2    8f34c303855f   17 hours ago    146 MB
```

Remove an older image tag:

```bash theme={null}
docker rmi nginx:1.20.2
```

Example output:

```text theme={null}
Untagged: docker.io/library/nginx:1.20.2
Deleted: 8f34c303855f0e55ca018386ff45cf47b1d7da554ab746b1c60049ebcf12d42c
[aaron@LFCS-CentOS ~]$
```

Creating and running containers

* By default, running without -d attaches your terminal to the container's stdout/stderr. Use Ctrl+C to stop.

Run in the foreground (attached):

```bash theme={null}
docker run nginx
```

Run detached (background):

```bash theme={null}
docker run -d nginx
# outputs container ID, e.g.:
# 92a87f978de3...
```

List running containers:

```bash theme={null}
docker ps
```

List all containers (running and stopped):

```bash theme={null}
docker ps --all
```

Stop and remove containers:

```bash theme={null}
docker stop <container-name-or-id>
docker rm <container-name-or-id>
```

Notes on safe image removal:

* docker rmi fails if an image is in use by any container. Preferred safe removal sequence:
  1. Stop containers: docker stop \<container>
  2. Remove containers: docker rm \<container>
  3. Remove image: docker rmi \<image>

Naming containers and exposing ports

* Assign a name and publish ports with --name and -p HOST:CONTAINER. Example: run nginx named mywebserver with host port 8080 mapped to container port 80:

```bash theme={null}
docker run -d -p 8080:80 --name mywebserver nginx
# Example returned container ID:
# 7953475436b9...
```

Testing the web server with netcat

* Use netcat (nc) to query the server. Pass host and port as separate arguments (no colon):

```bash theme={null}
nc localhost 8080
GET /
```

You should receive the nginx default index.html content:

```html theme={null}
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>
```

Press Ctrl+C to exit nc.

<Callout icon="warning" color="#FF6B6B">
  Ports below 1024 are privileged. To bind host port 80 to a container, run the command with elevated privileges (sudo) or map a non-privileged host port (>=1024).
</Callout>

Binding to privileged port 80 (example):

```bash theme={null}
sudo docker run -d -p 80:80 --name mywebserver nginx
```

Getting help and Podman-specific options

* Get detailed help for any command with --help:

```bash theme={null}
docker run --help
docker rm --help
# or
podman run --help
```

Podman rm options (example excerpt):

```text theme={null}
podman rm [options] CONTAINER [CONTAINER...]

Examples:
  podman rm imageID
  podman rm mywebserver myflaskserver 860a4b23
  podman rm --force --all
  podman rm -f c684f0d469f2

Options:
  -a, --all           Remove all containers
  -f, --force         Force removal of a running or unusable container
  -v, --volumes       Remove anonymous volumes associated with the container
  -t, --time uint     Seconds to wait for stop before killing the container (default 10)
  ...
```

Quick reference: common Docker/Podman commands

| Action                     | Command                                                       |
| -------------------------- | ------------------------------------------------------------- |
| Search registry            | `docker search <term>`                                        |
| Pull image                 | `docker pull \<image>`                                        |
| List local images          | `docker images`                                               |
| Run container (foreground) | `docker run \<image>`                                         |
| Run detached               | `docker run -d -p <host>:\<container> --name <name> \<image>` |
| List running containers    | `docker ps`                                                   |
| List all containers        | `docker ps --all`                                             |
| Stop container             | `docker stop \<container>`                                    |
| Remove container           | `docker rm \<container>`                                      |
| Remove image               | `docker rmi \<image>`                                         |

Links and references

* [Podman documentation](https://podman.io/)
* [Containers configuration (containers.conf / registries.conf)](https://github.com/containers/image/blob/main/docs/containers-registries.5.md)
* [Docker CLI reference](https://docs.docker.com/engine/reference/commandline/cli/)

This concludes the short hands-on introduction to pulling images, running containers, mapping ports, and cleaning up images. Practice these commands in a lab environment to build confidence and reinforce container lifecycle management.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/linux-professional-institute-lpic-1-exam-101/module/78ca0fa8-2083-408a-bf8a-2775b09fbf1d/lesson/a44e2a00-f21e-41d2-b33d-4a45ef05d395" />
</CardGroup>
