0.2-Managing Container With Podman
0.2-Managing Container With Podman
A good way to start learning about containers is to work with individual containers on
a single server acting as a container host. Red Hat Enterprise Linux provides a set of
container tools that you can use to do this, including:
podman, which directly manages containers and container images.
skopeo, which you can use to inspect, copy, delete, and sign images.
buildah, which you can use to create new container images.
These tools are compatible with the Open Container Initiative (OCI). They can be
used to manage any Linux containers created by OCI-compatible container engines,
such as Docker. These tools are specifically designed to run containers under Red Hat
Enterprise Linux on a single-node container host.
• The registry_name is the name of the registry storing the image. It is usually
the fully qualified domain name of the registry.
• The tag identifies the image version. If the image name includes no image tag,
then latest is assumed.
Running Containers
podman pull :- To run a container on your local system, you must first
pull a container image. Use Podman to pull an image from a
registry. You should always use the fully qualified image
name when pulling images. The podman pull command
pulls the image you specify from the registry and saves it
locally:
eg:
[user@host ~] $ podman pull registry.access.redhat.com/ubi8/ubi:latest
podman images :- Podman stores images locally and you can list them
using the podman images command:
eg:
[user@host ~] $ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.access.redhat.com/ubi8/ubi latest a1f8c9699786 5 weeks ago 211 MB
The preceding output shows that the image tag is latest and that the image ID is
a1f8c96699786.
podman run :- This command is used to run a container from image.
When you execute a podman run command, you create and
start a new container from a container image. Use the -it
options to interact with the container, if required. The -it
options allocate a terminal to the container and allow you to
send keystrokes to it.
eg:
[user@host ~] $ podman run -it registry.access.redhat.com/ubi8/ubi:latest
[root@8b032455db1a /]#
Important
If you run a container using the fully qualified image name, but the image is not yet
stored locally, then the podman run command first pulls the image from the
registry, and then runs.
Note
Many Podman flags also have an alternative long form; some of these are explained
below.
-t is equivalent to --tty, meaning a pseudo-tty (pseudo-terminal) is allocated for
the container.
-i is the same as – interactive, When this option is used, the container accepts
standard input.
-d, or its long form --detach, means the container runs in the background
(detached). When this option is used, Podman runs the container in the background
and displays its generated container ID.
When referencing a container, Podman recognizes either the container name or the
generated container ID. Use the --name option to set the container name when
running the container with Podman. Container names must be unique. If the podman
run command includes no container name, Podman generates a unique random name.
Note
Note that the latest tag is assumed when no tag is explicitly specified.
eg:
[user@host ~] $ podman run -it --name=rhel8 registry.access.redhat.com/ubi8/
ubi /bin/bash
podman run --rm :- command is used to run a quick command in a
container without interacting with it, and then remove
the container once the command is completed.
Eg:
[user@host ~]$ podman run --rm registry.access.redhat.com/ubi8/ubi cat
/etc/os-release
Lab Exercise:
4. Pull a container image from the registry with the fully qualified name using the
podman pull command.
5. Run a container from the image, connect it to the terminal, assign it a name,
and then start an interactive bash shell using the podman run command. The
latest tag is assumed since no tag is specified:
6. List running processes within the container. You will see only those processes
running in the container. You will not see any other processes that are running
on the server.
bash-4.4$ ps aux
bash-4.4$ exit