0% found this document useful (0 votes)
2 views7 pages

Containers Commands Notes

The document provides an overview of various Podman commands related to container management, including 'podman run', 'podman ps', 'podman stop', 'podman start', 'podman restart', 'podman rm', and 'podman exec'. Each command is explained with its purpose, basic syntax, common usage examples, and explanations of how they function. The document emphasizes the combination of functionalities and the specific use cases for each command to manage containers effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Containers Commands Notes

The document provides an overview of various Podman commands related to container management, including 'podman run', 'podman ps', 'podman stop', 'podman start', 'podman restart', 'podman rm', and 'podman exec'. Each command is explained with its purpose, basic syntax, common usage examples, and explanations of how they function. The document emphasizes the combination of functionalities and the specific use cases for each command to manage containers effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

EX_188_Images related commands

1.Podman run:

✅ Purpose

To create and start a container from a specified image, with options to manage:

 Naming

 Background execution

 Port mapping

 Cleanup behaviour

 User permissions

✅ Basic Syntax (for container management)

podman run [OPTIONS] IMAGE [COMMAND] [ARG...]

✅ Common Options

Option Description

-d Run container in background (detached mode)

--name Assign a custom name to the container

-p HOST:CONTAINER Map host port to container port

--rm Auto-remove container after it exits

-it Run interactively with TTY (useful for shells)

📌Example

🧪 Command

podman run -d --name myApp -p 8080:80 registry.access.redhat.com/ubi8/ubi:latest

🔍 Explanation

Part Meaning

podman run Create and start a new container

-d Run in detached (background) mode

--name myApp Name the container myApp (for easy reference)

-p 8080:80 Map host port 8080 to container port 80

registry.access.redhat.com/ubi8/ubi:latest Use the Red Hat UBI 8 base image (latest tag)

🧾 Result

 A container named myApp runs in the background

 It uses the UBI8 image from Red Hat’s registry

 You can access its service via: http://localhost:8080

1
EX_188_Images related commands
Question: Does it combine the functionalities of both podman create and podman start
commands ?

Yes, exactly ✅

The command: podman run ...

combines the functionality of:

🔧 podman create

→ Creates a new container from an image, but does not start it.

▶️podman start

→ Starts a previously created (but stopped) container.

📦 So when you run:

podman run -d --name myApp -p 8080:80 registry.access.redhat.com/ubi8/ubi:latest

It is functionally equivalent to:

# Step 1: Create container

podman create -d --name myApp -p 8080:80 registry.access.redhat.com/ubi8/ubi:latest

# Step 2: Start it

podman start myApp

✅ Summary

Command Behavior

podman create Creates a container (stopped)

podman start Starts a created or stopped container

podman run Creates and immediately starts a container

Use podman run when you want quick one-step execution. Use create + start when you
want more control or to configure the container before starting it.

2.Podman ps:

The podman ps command is used to list running containers on your system, similar to
docker ps.

✅ Basic Syntax: podman ps [options]

🔍 Common Usage:

🟢 1. List all running containers: podman ps

 Shows only currently running containers by default.

🟠 2. List all containers (running + stopped): podman ps -a

 -a or --all: Show all containers, not just running ones.

🟣 3. Display containers with full details:

podman ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}"

2
EX_188_Images related commands
 Custom output format using Go templates.

🔵 4. Filter containers: podman ps --filter "status=exited"

 Filters containers by status (running, exited, etc.).

📘 Example Output:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS


NAMES

f3c4c8b9d6ab registry.access.redhat.com/ubi8 /bin/bash 10 minutes ago Up 10 minutes


0.0.0.0:8080->80/tcp myApp

🧠 Use Case with Explanation:

If you ran this command earlier:

podman run -d --name myApp -p 8080:80 registry.access.redhat.com/ubi8/ubi:latest

Then running: podman ps

Will show a container like this:

CONTAINER ID IMAGE STATUS PORTS NAMES

abcd1234ef56 registry.access.redhat.com/ubi8/ubi Up 5 minutes 0.0.0.0:8080->80/tcp


myApp

 ✅ Container is running in detached mode

 ✅ Published port: 8080 on host mapped to 80 in container

 ✅ Name: myApp

3.Podman stop:

The podman stop command is used to gracefully stop running containers.

✅ Basic Syntax: podman stop <container_name_or_id> [<more_containers>...]

🔧 What it does:

 Sends a SIGTERM to the container process (gives it a chance to shut down).

 Waits for the container to exit (default timeout: 10 seconds).

 If it doesn’t stop in time, sends SIGKILL to force stop.

📘 Common Examples:

🟢 1. Stop a container by name: podman stop myApp

Stops the container named myApp.

🔵 2. Stop a container by ID: podman stop f3c4c8b9d6ab

Stops the container with the specified ID.

🟠 3. Stop multiple containers at once: podman stop myApp dbContainer redisContainer

🔴 4. Force kill after custom timeout: podman stop -t 5 myApp

 -t or --timeout: wait 5 seconds before sending SIGKILL.

✅ Example Flow:
3
EX_188_Images related commands
If you ran:

podman run -d --name myApp -p 8080:80 registry.access.redhat.com/ubi8/ubi:latest

To stop it: podman stop myApp

To confirm it's stopped:

podman ps # Won’t show it

podman ps -a # Shows with status: Exited

4.Podman start:
The podman start command is used to start one or more stopped containers.

✅ Basic Syntax: podman start <container_name_or_id> [<more_containers>...]

🔧 What it Does:

 Restarts a previously stopped container.

 The container resumes execution with its last-known configuration (image, command,
ports, etc.).

 It does not create a new container — it reuses an existing one.

📘 Common Examples:

🟢 1. Start a container by name: podman start myApp

Starts a container named myApp that was previously stopped.

🔵 2. Start a container by ID: podman start 1a2b3c4d5e6f

🟠 3. Start multiple containers: podman start myApp redis db

🔴 4. Start a container and attach to its output: podman start -a myApp

 -a or --attach: Attach your terminal to the container's standard output.

 Useful for debugging or interactive containers.

🧠 Example Flow:

If you ran this earlier:

podman run -d --name myApp -p 8080:80 registry.access.redhat.com/ubi8/ubi:latest

And then stopped it: podman stop myApp

You can bring it back with: podman start myApp

To confirm: podman ps

5.Podman restart:

The podman restart command is used to stop and then start one or more containers —
essentially performing a restart.

✅ Basic Syntax: podman restart <container_name_or_id> [<more_containers>...]

🔧 What it Does:

 Gracefully stops the running container(s) (SIGTERM followed by SIGKILL after


timeout).
4
EX_188_Images related commands
 Then restarts them with the same configuration (name, image, ports, etc.).

 Useful when you want to refresh the container state or apply changes to mounted
volumes.

📘 Common Examples:

🟢 1. Restart a container by name: podman restart myApp

🔵 2. Restart using container ID: podman restart 1a2b3c4d5e6f

🟠 3. Restart multiple containers at once: podman restart myApp db redis

🔴 4. Restart with custom timeout: podman restart -t 5 myApp

 -t or --time: Time (in seconds) to wait before killing the container if it doesn't stop
gracefully.

🧠 Example Workflow:

You initially ran: podman run -d --name myApp -p 8080:80


registry.access.redhat.com/ubi8/ubi:latest

Now you want to restart it: podman restart myApp

To confirm it restarted: podman ps

Command Purpose

podman start Starts a stopped container

podman restart Stops and restarts a running container

6.Podman rm:

The podman rm command is used to remove (delete) one or more stopped containers from
your system.

✅ Basic Syntax: podman rm <container_name_or_id> [<more_containers>...]

🔧 What It Does:

 Deletes the container's filesystem, metadata, and runtime config.

 Does not remove the image used to create the container.

 The container must be stopped before you can remove it, unless you use -f.

📘 Common Examples:

🟢 1. Remove a stopped container by name: podman rm myApp

🔵 2. Remove multiple containers: podman rm myApp db redis

🔴 3. Force remove a running container: podman rm -f myApp

 -f or --force: Stops the container first (if running), then removes it.

🟠 4. Remove all stopped containers: podman container prune

This is a safer alternative to deleting all containers manually.

🧠 Example Flow:

5
EX_188_Images related commands
You previously ran: podman run -d --name myApp -p 8080:80
registry.access.redhat.com/ubi8/ubi:latest

Then: podman stop myApp followed by podman rm myApp

This will completely delete the myApp container instance.

To confirm it's gone: podman ps -a

⚠️Important Notes:

 You cannot reuse the same container name (myApp) until it's removed.

 Removing a container does not affect volumes, unless you explicitly mounted a
volume and want to clean it separately.

7. podman exec:

The podman exec command is used to run a command inside a running container.

✅ Basic Syntax: podman exec [options] <container_name_or_id> <command> [args...]

🔧 What It Does:

 Executes a new process in an already running container.

 Useful for inspecting or interacting with the container without logging in.

 Often used to run tools like bash, sh, ls, cat, etc.

📘 Common Examples:

🟢 1. Run a shell inside the container: podman exec -it myApp /bin/bash

 -i → interactive (keep stdin open)

 -t → pseudo-TTY (allocate terminal)

Opens an interactive Bash shell inside the myApp container.

🔵 2. Run a single command inside the container: podman exec myApp ls /var/www

Lists contents of /var/www in the container.

🟠 3. Check running processes in the container: podman exec myApp ps aux

🔴 4. Print environment variables: podman exec myApp env

🧠 Example Flow:

If you ran a container like:

podman run -d --name myApp -p 8080:80 registry.access.redhat.com/ubi8/ubi:latest

Then you can enter the shell like this: podman exec -it myApp /bin/bash

Now you're "inside" the container and can inspect or debug it interactively.

🔄 Related Commands:

Command Purpose

podman run Start a new container and run a command

podman exec Run a command in a running container

6
EX_188_Images related commands
Command Purpose

podman attach Attach to a main process of a container

You might also like