0% found this document useful (0 votes)
10 views6 pages

Deploying and Managing Containers

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Deploying and Managing Containers

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 11 | Run Containers

Guided Exercise

Deploy Containers
In this exercise, you use container management tools to build an image, run a container, and
query the running container environment.

Outcomes
• Configure a container image registry and create a container from an existing image.
• Create a container by using a container file.
• Copy a script from a host machine into containers and run the script.
• Delete containers and images.

Before You Begin


As the student user on the workstation machine, use the lab command to prepare your
system for this exercise.

This command prepares your environment and ensures that all required resources are
available.

[student@workstation ~]$ lab start containers-deploy

Instructions
1. Log in to the servera machine as the student user.

[student@workstation ~]$ ssh student@servera


...output omitted...
[student@servera ~]$

2. Install the container-tools meta-package.

[student@servera ~]$ sudo dnf install container-tools


[sudo] password for student: student
...output omitted...
Is this ok [y/N]: y
...output omitted...
Complete!

3. Configure the [Link] classroom registry in your home directory.


Log in to the container registry with admin as the user and redhat321 as the password.

3.1. Create the /home/student/.config/containers directory.

[student@servera ~]$ mkdir -p /home/student/.config/containers

RH134-RHEL9.0-en-2-20220609 339
Chapter 11 | Run Containers

3.2. Create the /home/student/.config/containers/[Link] file with


the following contents:

unqualified-search-registries = ['[Link]']

[[registry]]
location = "[Link]"
insecure = true
blocked = false

3.3. Verify that the classroom registry is added.

[student@servera ~]$ podman info


...output omitted...
registries:
[Link]:
Blocked: false
Insecure: true
Location: [Link]
MirrorByDigestOnly: false
Mirrors: null
Prefix: [Link]
search:
- [Link]
...output omitted...

3.4. Log in to the classroom registry.

[student@servera ~]$ podman login [Link]


Username: admin
Password: redhat321
Login Succeeded!

4. Run the python38 container in detached mode from an image with the python 3.8
package and based on the ubi8 image. The image is hosted on a remote registry.

4.1. Search for a python-38 container in the [Link] registry.

[student@servera ~]$ podman search [Link]/


NAME DESCRIPTION
...output omitted...
[Link]/ubi8/python-38
[Link]/ubi8/httpd-24
[Link]/rhel8/php-74

4.2. Inspect the image.

340 RH134-RHEL9.0-en-2-20220609
Chapter 11 | Run Containers

[student@servera ~]$ skopeo inspect \


docker://[Link]/ubi8/python-38
...output omitted...
"description": "Python 3.8 available as container is a base platform for
building and running various Python 3.8 applications and frameworks.
...output omitted...

4.3. Pull the python-38 container image.

[student@servera ~]$ podman pull [Link]/ubi8/python-38


Trying to pull [Link]/ubi8/python-38:latest...
...output omitted...
671cc3cb42984e338733ebb5a9a68e69e267cb7f9cb802283d3bc066f6321617

4.4. Verify that the container is downloaded to the local image repository.

[student@servera ~]$ podman images


REPOSITORY TAG IMAGE ID CREATED
SIZE
[Link]/ubi8/python-38 latest 671cc3cb4298 5 days ago
901 MB

4.5. Start the python38 container.

[student@servera ~]$ podman run -d --name python38 \


[Link]/ubi8/python-38 sleep infinity
004756b52d3d3326545f5075594cffa858afd474b903288723a3aa299e72b1af

4.6. Verify that the container was created.

[student@servera ~]$ podman ps


CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS NAMES
004756b52d3d [Link]/ubi8/python-38:latest sleep infinity
About a minute ago Up About a minute ago python38

5. Build a container image called python36:1.0 from a container file, and use the image to
create a container called python36.

5.1. Change into the /home/student/python36 directory and examine the container
file called Containerfile.

[student@servera ~]$ cd /home/student/python36


[student@servera python36]$ cat Containerfile
FROM [Link]/ubi8/ubi:latest
RUN dnf install -y python36
CMD ["/bin/bash", "-c", "sleep infinity"]

5.2. Create the container image from the container file.

RH134-RHEL9.0-en-2-20220609 341
Chapter 11 | Run Containers

[student@servera python36]$ podman build -t python36:1.0 .


STEP 1/3: FROM [Link]/ubi8/ubi:latest
...output omitted...
STEP 2/3: RUN dnf install -y python36
...output omitted...
STEP 3/3: CMD ["/bin/bash", "-c", "sleep infinity"]
...output omitted...
Successfully tagged localhost/python36:1.0
80e68c195925beafe3b2ad7a54fe1e5673993db847276bc62d5f9d109e9eb499

5.3. Verify that the container image exists in the local image repository.

[student@servera ~]$ podman images


REPOSITORY TAG IMAGE ID CREATED
SIZE
localhost/python36 1.0 80e68c195925 3 minutes ago
266 MB
[Link]/ubi8/python-38 latest 671cc3cb4298 5 days ago
901 MB
[Link]/ubi8/ubi latest fca12da1dc30 4 months ago
235 MB

5.4. Inspect the python36 container.

[student@servera ~]$ podman inspect localhost/python36:1.0


...output omitted...
"created": "2022-04-26T20:58:13.448031264Z",
"created_by": "/bin/sh -c dnf install -y python36",
"comment": "FROM [Link]/ubi8/ubi:latest"
},
{
"created": "2022-04-26T20:58:14.057396235Z",
"created_by": "/bin/sh -c #(nop) CMD [\"/bin/bash\", \"-c\",
\"sleep infinity\"]",
...output omitted...

5.5. Create the python36 container.

[student@servera ~]$ podman create --name python36 localhost/python36:1.0


3db4eabe9043224a7bdf195ab5fd810bf95db98dc29193392cef7b94489e1aae

5.6. Start the python36 container.

[student@servera ~]$ podman start python36


python36

5.7. Verify that the container is running.

342 RH134-RHEL9.0-en-2-20220609
Chapter 11 | Run Containers

[student@servera ~]$ podman ps


CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS NAMES
004756b52d3d [Link]/ubi8/python-38:latest sleep infinity
33 minutes ago Up 33 minutes ago python38
3db4eabe9043 localhost/python36:1.0 /bin/bash -c
slee... About a minute ago Up 42 seconds ago python36

6. Copy the /home/student/[Link] script into the /tmp directory of the running
containers and run the script on each container.

6.1. Copy the /home/student/[Link] python script into the /tmp directory in
both containers.

[student@servera ~]$ podman cp /home/student/[Link] python36:/tmp/[Link]


[student@servera ~]$ podman cp /home/student/[Link] python38:/tmp/[Link]

6.2. Run the Python script in both containers, and then run the Python script on the host.

[student@servera ~]$ podman exec -it python36 python3 /tmp/[Link]


This script was not run on the correct version of Python
Expected version of Python is 3.8
Current version of python is 3.6
[student@servera ~]$ podman exec -it python38 python3 /tmp/[Link]
This script was correctly run on Python 3.8
[student@servera ~]$ python3 /home/student/[Link]
This script was not run on the correct version of Python
Expected version of Python is 3.8
Current version of python is 3.9

7. Delete containers and images.

7.1. Stop both containers.

[student@servera ~]$ podman stop python36 python38


...output omitted...
python38
python36

7.2. Remove both containers.

[student@servera ~]$ podman rm python36 python38


3db4eabe9043224a7bdf195ab5fd810bf95db98dc29193392cef7b94489e1aae
004756b52d3d3326545f5075594cffa858afd474b903288723a3aa299e72b1af

7.3. Remove both container images.

RH134-RHEL9.0-en-2-20220609 343
Chapter 11 | Run Containers

[student@servera ~]$ podman rmi localhost/python36:1.0 \


[Link]/ubi8/python-38:latest \
[Link]/ubi8/ubi
Untagged: localhost/python36:1.0
Untagged: [Link]/ubi8/python-38:latest
Deleted: 80e68c195925beafe3b2ad7a54fe1e5673993db847276bc62d5f9d109e9eb499
Deleted: 219e43f6ff96fd11ea64f67cd6411c354dacbc5cbe296ff1fdbf5b717f01d89a
Deleted: 671cc3cb42984e338733ebb5a9a68e69e267cb7f9cb802283d3bc066f6321617

Finish
On the workstation machine, change to the student user home directory and use the lab
command to complete this exercise. This step is important to ensure that resources from previous
exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish containers-deploy

This concludes the section.

344 RH134-RHEL9.0-en-2-20220609

Common questions

Powered by AI

Challenges in scripting automation tasks include environment discrepancies, differing library dependencies, and network configuration variations. These can be mitigated by ensuring consistent base images, using environment variables for configurations, implementing extensive test cases for scripts, and adopting container orchestration tools to manage environment-specific automations effectively .

Creating a container from an existing image is straightforward and advantageous for standardized deployments, providing speed, consistency, and reliability using pre-built images. In contrast, creating a container from a container file involves building an image from the ground up, allowing customization of the environment, especially beneficial for complex, unique applications needing specific setups. The choice between the two depends on whether custom configurations or speed and simplicity are prioritized .

Creating a custom container image from a container file allows developers to define specific environments and dependencies their applications need, ensuring consistency across different deployments and environments. This approach also enhances reproducibility, reduces deployment errors, and enables optimization of resources by only including necessary components .

Removing containers and images helps maintain a clean and efficient environment by freeing up system resources, reducing clutter, and minimizing potential security risks associated with outdated or unused containers. This practice is vital for performance optimization, ensuring only relevant and secure images and containers occupy the system .

Using a meta-package such as 'container-tools' bundles multiple tools essential for container management, simplifying the installation process and ensuring that all dependencies are addressed. This streamlines setup and maintenance, reduces compatibility issues, and provides a comprehensive suite of tools necessary for efficiently building, running, and managing containers .

Verifying the download and availability of a container image ensures that the image is correctly pulled, reducing errors during deployment and guaranteeing that the container can start with the intended software environment. This step is crucial for minimizing downtime and enabling troubleshooting during production rollouts .

Setting the unqualified-search-registries configuration ensures that when a container image is specified without a fully qualified name, the system searches only the specified registries. This configuration enhances security by controlling required images' sources and optimizes retrieval times by targeting the preferred registries, crucial for secure and efficient deployments .

Running a container in detached mode allows the container to run in the background, freeing up the terminal for other tasks. This mode is particularly useful for long-running services, enabling real-time applications to function continuously without occupying the user's interactive session, thus enhancing multitasking and seamless operations .

Configuring a container image registry like registry.lab.example.com allows a user to pull container images needed for deployment, ensuring that they have authenticated access and correct settings like security configurations for image retrieval. This setup is crucial for pulling the correct images for applications and maintaining secure access, ultimately facilitating the building, running, and management of containers .

Running scripts inside containers allows for automated environment set-up, running tests, or configuring services, integral to containerized application management. It supports CI/CD workflows, ensures uniformity of operations across environments, and facilitates integration of other services through scripting. This practice enhances reproducibility and operational efficiency within container management frameworks .

You might also like