This is part of the independent and unofficial RHCSA Exam Study Guide series providing free š¤ resources to prepare for the exam.
This post covers the objectives under the section:
“MANAGE CONTAINERS”
It contains two main parts:
- Resources: with links to learn and practice for each objective.
- Cheatsheet: containing some examples of commands and actions performed in each objective (when applied).
š Resources:
FIND AND RETRIEVE CONTAINER IMAGES FROM A REMOTE REGISTRY
- š Chapter 3. Working with container images (items 3.1. to 3.5.)
INSPECT CONTAINER IMAGES
PERFORM CONTAINER MANAGEMENT USING COMMANDS SUCH AS PODMAN AND SKOPEO
(Covered in previous and next items)
PERFORM BASIC CONTAINER MANAGEMENT SUCH AS RUNNING, STARTING, STOPPING, AND LISTING RUNNING CONTAINERS
RUN A SERVICE INSIDE A CONTAINER
CONFIGURE A CONTAINER TO START AUTOMATICALLY AS A SYSTEMD SERVICE
ATTACH PERSISTENT STORAGE TO A CONTAINER
š Cheatsheet:
(Requires RHEL 8.3 or above, and container-tools
module)
FIND AND RETRIEVE CONTAINER IMAGES FROM A REMOTE REGISTRY
Configure (user-level) container registries
- create
$HOME/.config/containers/registries.conf
ā” file to override the system-wide settings, and configure user level container regisitries.
[registries.search] registries = ['registry.access.redhat.com', 'registry.redhat.io', 'docker.io'] [registries.insecure] registries = [] [registries.block] registries = []
- create
podman search caddy
ā” searches the predefined container registries for container images containing the word ‘caddy’.podman login quay.io
ā” authenticates to ‘quay.io’ container registry.podman search quay.io/postgresql-10
ā” searches for the particular image on the specified registry.podman search -f is-official --limit 3 --no-trunc alpine
ā” searches for a particular image on all repositories, and displays only official images, maximum of 3, and full description.podman pull registry.redhat.io/ubi8/ubi
ā” pull specified image from specified registry.
INSPECT CONTAINER IMAGES
podman images
ā” lists images downloaded to the system or created on the system.podman inspect caddy
ā” inspect local image named ‘caddy’.skopeo inspect docker://registry.redhat.io/ubi8/ubi-init | less
ā” inspect remote image, usingless
pager.
PERFORM CONTAINER MANAGEMENT USING COMMANDS SUCH AS PODMAN AND SKOPEO
podman tag docker.io/library/mariadb localstable
ā” addlocalstable
tag to local image.
PERFORM BASIC CONTAINER MANAGEMENT SUCH AS RUNNING, STARTING, STOPPING, AND LISTING RUNNING CONTAINERS
podman exec myubi ls -la
ā” executels -la
command inside themyubi
running container, and detach.podman attach myubi
ā” attach tomyubi
running container.podman stop myubi && podman rm myubi
ā” stop and removemyubi
container.podman run --rm alpine ls /etc
ā” start container fromalpine
image, run the commandls /etc
, exit and remove the container.podman run --name=myalpine -it alpine /bin/sh
ā” start container fromalpine
image, in interactive mode providing the/bin/sh
shell, applymyalpine
name to the container.podman run -d mysql
ā” start container frommysql
image and detach the session, container keeps running.podman ps -a
ā” show running and stopped containers.podman start myubi
ā” start container namedmyubi
detached.podman start -a -i myubi
ā” start container namedmyubi
attached and interactive mode.
RUN A SERVICE INSIDE A CONTAINER
item
ā” description.
CONFIGURE A CONTAINER TO START AUTOMATICALLY AS A SYSTEMD SERVICE
podman create --name myhttpd docker.io/library/httpd
ā” create a container (do not start/run it).podman generate systemd --name myhttpd > ~/.config/systemd/user/container-myhttpd.service
ā” generate the container’s systemd unit file (create directory if needed). Inside the unit file,ExecStart
runpodman start
command so, the container must exist in the host system.Auto-generate a systemd unit file that auto-generate a container:
Create a new user (i.e.:
containeruser
) and open a terminal session with it.podman create --name myhttpd2 httpd
ā” create a container (do not start/run it).podman generate systemd --new --files --name myhttp2
ā” generate the container’s systemd unit file. Inside the unit file,ExecStart
runpodman run
command so, the container will be created on start.cp container-myhttpd2.service ~/.config/systemd/user/
ā” install it as user service.
Auto-starting containers using systemd
systemctl --user daemon-reload
systemctl --user --now enable container-myhttpd.service
loginctl enable-linger && loginctl show-user containeruser
ā” make the service autostart without the need forcontaineruser
to log in.- verify with:
systemctl --user status container-myhttpd.service
systemctl --user | grep container
podman ps -a
ATTACH PERSISTENT STORAGE TO A CONTAINER
podman run --name="log_test" -v /dev/log:/dev/log --rm ubi logger "LOG THIS"
ā” create containerlog_test
, mount the host/dev/log
directory inside the container, create log message from the container.
MORE EXAMPLES
podman info
ā” display podman system information.podman inspect --format='{{.Config.ExposedPorts}}' myalpine
ā” inspect local container namedmyalpine
displaying only the selected item from the JSON object.podman run -dp 8080:80 --name http-serv docker.io/library/httpd
ā” create a container from the image, name it ashttp-serv
and expose it’s port n. 80 to port 8080 in the host system.podman run -it -e HISTSIZE -e SECRET="Mysecret" --name ubi8-vars ubi8
ā” create containerubi8-vars
fromubi8
image, in interactive mode, setting up the specified environment variables.podman port http-serv
ā” check thehttp-serv
container port mapping status.podman unshare ls -la myshares
ā” showsmyshares
directory properties, UID, GID, etc, as it is viewed by a rootless container.podman unshare chown 1000:1000 -R myshares
ā” change user and group owner inside the ‘user namespace’ formyshares
directory recursively.podman run -u 1000 -it -v /home/user1/myshares:/mnt/persistent:Z myubi /bin/bash
ā” start container frommyubi
image, in interactive mode (bash
shell), as user1000
, mountmyshares
directory at/mnt/persistent
with a private unshared label (SELinux).<Ctrl>
+p
,<Ctrl>
+q
ā” detach from the container’s interactive mode and go back to the host shell (container keeps running).
podman volume create hostvolume
ā” create new volume.podmand volume inspect hostvolume
ā” display information about the volume.mntPoint=$(podman volume inspect hostvolume --format {{.Mountpoint}})
ā” save the volume mountpoint tomntPoint
varable for easier manipulation.podman run -it -v hostvolume:/mnt/sharedvol myubi /bin/bash
ā” start container formmyubi
image, interactive mode in abash
shell, mount thehostvolume
created at/mnt/sharedvol
directory.
š Congratulations!
You achieved the end of the learning for the RHCSA Exam!
(practice, reinforce, excercise, etc, check notes at:)
Red Hat Certified System Administrator (RHCSA) Exam Study Guide
Useful links & references:
Enable Sysadmin (a blog from Red Hat)
Footnotes:
- Follow me on Twitter to get more posts like this and other quick tips in your feed.
- If you have any doubts or tips about this article, Iād appreciate knowing and discussing it via email.
- Do you have any other Linux tips? Would you like to publish that in this blog? Please send an email to all drops.
- As English is not my native language, I apologize for the errors. Corrections are welcome.
- Contact: contact [@] alldrops [.] info.