Hello, and welcome to today's video presentation on running a container using Podman on Oracle
Linux 8.
This video provides a series of demos covering how to use the podman command to run a container.
So let us get started.
First, open a terminal and connect to your host system.
In this exercise, the host system is a fully patched Oracle Linux 8 instance on Oracle
Cloud Infrastructure.
This instance also has the podman package pre-installed.
If the package is not available, see our other videos on this topic at oracle.com/goto/oraclelinuxlearning
under Virtualization and Container Videos.
To recap a previous video, here is a quick overview of the terms image and container.
An image is a non-changeable file containing a minimal operating system, libraries, source
code, tools, and other files needed to run applications.
Whereas, a container is the virtualized run-time instance of an image.
With those terms covered, start the demo by checking what images exist on the local disk
for the current user by typing "podman images."
The output displays the existence of an oraclelinux image with a tag reference of 8.
Using this image, create an interactive container by typing "podman create -d -ti --name oracleshell
oraclelinux:8 /bin/bash".
In this case, the "podman create" command generates a writeable container using the
image specified and prepares it for running the /bin/bash shell command.
The -d option sends the container process to the background as a daemon, and the -ti
allocates an interactive pseudo-TTY session when the container is running.
Since we used the create command, Podman generates the container, provides it an ID, but does
not start the container.
To show a list of containers, type "podman ps -a," where the -a option displays both
the running and non-running containers.
The list of containers displayed is restricted to those owned by the oracle user account,
as the oracle user issued the ps command.
The newly generated container remains in a created status and is not currently running.
Start and run the container by typing "podman start -ia oracleshell."
The start command's options (-ia) will start the container named oracleshell and then attach
to the container's standard input.
Hit Enter.
The running container provides an interactive bash shell prompt based on the command passed
during its creation.
The prompt displayed by the container is the user root, followed by the at symbol and the
container_id.
Test a few common Linux commands in the container by typing "ls," "whoami," and "uname -a."
With the Linux commands working, leave the container shell by typing "exit" and the prompt
returns to the host system prompt.
Check the status of the container by again typing "podman ps -a."
By typing exit to leave the interactive shell, the container stopped and entered an exited
status.
To start the same container again without instantly attaching to it, type "podman start
oracleshell."
Recheck the container status with "podman ps -a."
The container is now in an up status, indicating it's running.
Connect to the container and run a single command by typing "podman exec oracleshell
cat /etc/oracle-release."
The exec command will run the single command passed within the specified container, display
the output, and then return to the hosts prompt while leaving the container running.
Hit Enter.
The command returns the contents of the /etc/oracle-release file.
Next, connect again to the container with an interactive shell by typing "podman attach
oracleshell."
Like the last test, we want to leave the container and return to the host.
Rather than typing "exit" at the prompt, type the sequence "CTRL-p CTRL-q."
This time we detach from the container without causing it to stop.
Verify the container remained running by again checking its status with "podman ps -a."
The oracleshell container remains running in an up status.
Since we finished using this container, type "podman stop oracleshell" to return the container
to an exited status.
The next container example will use the 8-slim image and the podman run command.
Similar to the previous example, we need to create a container based on an image.
Using the "podman run" command, we will create and start the image in a single step by typing
"podman run -ti oraclelinux:8-slim /bin/bash."
The run command will first pull the image tagged as 8-slim from a configured repository
as it does not yet exist locally on disk.
The container is assigned a random name if you do not pass the --name option during creation.
By running the /bin/bash command, the container creates and starts an interactive shell.
If the container fails to run for some reason, you can try running podman in debugging mode
by adding the option --log-level debug before the run command, as shown on the screen.
[ silence ... podman --log-level debug run -ti oraclelinux:8-slim /bin/bash ]
The output will display debugging messages related to the running of the podman command.
The Linux host may also write additional details to journald, which is covered in other lessons
and outside this video's scope.
Hit Enter and the container runs and presents the generic bash prompt.
To see the random name assigned, switch to another terminal connected to the same host
machine, and type "podman ps."
The random name displays in the last column.
Now, return to the original terminal window.
With this example done, leave the container by typing "exit."
This process leaves the container created, but in a non-running exited status.
Again, verify this by typing "podman ps -a."
The last container example we will show runs just a single command and has the container
removed automatically after execution.
Type "podman run --rm oraclelinux:8-slim microdnf repolist."
The --rm option causes removal of the container after executing the specified command "microdnf
repolist."
The minimalistic microdnf command replaces the standard dnf command in the 8-slim image
to handle package tasks.
The result of running this command within the container is a list of the different dnf
repositories configured during the 8-slim image creation.
You can ignore the expected libdnf-WARNING displayed.
This message is due to the minimalistic configuration of the 8-slim image.
After reviewing the output, verify the container's automatic removal by typing "podman ps -a."
The list shows only the oracleshell and random-named container remains.
That completes this demo of running containers with podman.
To finish this video exercise, remove any containers created during these steps.
Using the information presented when typing "podman ps -a," type "podman stop" and pass
either the container_id or the -a option.
Using the -a option will stop all containers in a single step.
Once the containers stop, remove the containers by typing "podman rm" and pass the container_id
or the container_name.
Remove the first container in the list using the container_id and then remove the second
using the container_name.
Running "podman ps -a" once more will confirm the containers no longer exist.
Although the containers do not exist, the images pulled from the repository remain on
disk.
Type "podman images" to show the local images.
To remove an image, type "podman rmi" and pass the image_id shown in the "podman images"
output.
That completes this demonstration of running a container using Podman.
Thank you for watching this video and enjoy using Oracle Linux 8.
Please check our additional information on Oracle Linux 8 in the Oracle Linux 8 Documentation
or Oracle Linux Learning Library.