Podman Commands Flashcards

1
Q

Search for Images

A

podman search <Image_name></Image_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Download Image

A

podman pull <Image_Name></Image_Name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create Container

A

podman images (List Local Images)
podman ps -a (List active containers)

podman run -d –name <container_name> -p <port1:port2> <image_name></image_name></port1:port2></container_name>

To check if Container is Running

curl 127.0.0.1:8080

cat server_info.txt > server_info.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Creating a Persistent Container Volume

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Creating a Database Container with podman

A

podman run -d –name mysql-1 -v ~/db_dir:/var/lib/mysql:Z -e MYSQL_ROOT_PASSWORD=changeme -p 33061:3306 docker.io/library/mysql

podman ps

To validate if database is running

podman exec -it mysql-1 bash

container&*> mysql -pchangeme

mysql>show databases;

or

mysql -h localhost -P 33061 -u root -pchangeme –protocol=tcp -e “show databases;”

ls db_dir/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Create a Second Database Container -

Start the second MySQL container using the pulled image. The container should be started with a Podman-managed volume.

A

podman volume create db_vol

podman volume list

podman run -d –name mysql-2 -v db_vol:/var/lib/mysql/ -p 33062:3306 -e MYSQL_ROOT_PASSWORD=changeme mysql

podman ps

To validate database is running

podman exec -it mysql-2 bash

container&*> mysql -pchangeme

mysql>show databases;

or

mysql -h localhost -P 33062 -u root -pchangeme –protocol=tcp -e “show databases;”

podman volume inspect db_vol

Take the path from the Mountpoint and run the following command

ls /home/cloud_user/.local/share/containers/storage/volumes/db_vol/_data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Managing Containers with Registries

A

When you know the registries that you want to include you should do the following:

sudo vim /etc/containers/registries.conf

enter the info for the registries.search - registries = [‘registry-name’]

enter the info for the registries.insecure - registries = [‘registry-name’]

Now, next step is to login into the registry

podman login <registry>
username:
password:</registry>

Search image that you need

podman search llama-web

Inspect images to see if there are other versions than just the latest

skopeo inspect docker://<IMAGE_NAME> | less</IMAGE_NAME>

once you have the tag you can then pull the image that you want or create a container from it

podman pull <IMAGE_NAME>:v1.1</IMAGE_NAME>

podman run -d –name llama-web localhost:5000/llama-web:v1.1

podman images

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Tagging and Saving Images

A

In this scenario the images is already loaded and the container has been created.

podman ps -a

Check the default web page:
curl localhost:8080

Connect to the container:
podman exec -it web-1 bash

Change the default web page:
echo “Future Home of Llama-rama enterprises” > /usr/share/nginx/html/index.html

Exit out of the container:
exit

Verify the change was successful:
curl localhost:8080

Commit the Changes to a New Image and Tag the Image

podman commit web-1 localhost:5000/llama-rama-web

Verify the changes have been committed:
podman images

Clear your screen:
clear

View the image list:
podman images

Tag the new image as v1.0:
podman tag <IMAGE_NAME> <IMAGE_NAME>:v1.0</IMAGE_NAME></IMAGE_NAME>

View the image list to verify the tag:
podman images

Create a .tar Archive of the New Image
View the image list:

podman images

Create a .tar archive of the new image named llama-rama-web.tar:

podman save -o llama-rama-web.tar localhost:5000/llama-rama-web:v1.0

Confirm the .tar file exists:

ls -l llama-rama-web.tar

Publish the New Image to a Local Registry

Log in to the registry:
podman login localhost:5000

Use the cloud_user credentials for the Username and Password.

View the image list:
podman images

Push the llama-rama-web image with the v1.0 tag to the local registry:
podman push <IMAGE_NAME>:v1.0 <IMAGE_NAME>:v1.0</IMAGE_NAME></IMAGE_NAME>

Verify the image was successfully pushed:

podman search llama-rama-web

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Building a Custom Image Using Podman

A

Dockerfile Creation

Set Up a New Build Directory
List the files in the home directory:

ls

Create a new build directory:
mkdir my_build

Copy the Dockerfile, along with any .zip and .tar files, from /home/cloud_user and add them to the build directory:

cp *tar *zip Dockerfile my_build/

Move into the new directory:

cd my_build/

List the files:
ls
=====
Complete the Dockerfile
Edit the Dockerfile:

vim Dockerfile

Highlight the comments in a different color for easier readability:
:hi Comment ctermfg=grey

Under, Please use image
registry.access.redhat.com/ubi8/ubi:8.4, start the image with registry.access.redhat.com/ubi8/ubi:8.4:

FROM registry.access.redhat.com/ubi8/ubi:8.4

Set yourself as the maintainer:

MAINTAINER <NAME></NAME>

Add a description to the image next to

LABEL description=:”test llama-cart website”

Install nginx and unzip the packages into the image:

RUN yum install -y nginx unzip

Set a variable named PORT to a value of 90.

ENV PORT=90

Use the new variable to expose the port:

EXPOSE $PORT

Copy the nginx.zip file to /tmp/:

COPY nginx.zip /tmp/

Extract /tmp/nginx.zip to /etc/nginx and overwrite any existing files:

RUN unzip -o /tmp/nginx.zip -d /etc/nginx/

Extract llama_cart.tar to /usr/share/nginx/html/:

ADD llama_cart.tar /usr/share/nginx/html/

Set the workdir to /tar_file/ and copy llama_cart.tar to this directory without uncompressing it:

WORKDIR /tar_file/
COPY llama_cart.tar .

Set the container to start nginx with options -g and daemon off as overwritable options:
ENTRYPOINT [“nginx”]
CMD [“-g”, “daemon off;”]

Save and quit (remember to first press Escape):
:wq!
`
==========

Build and Test the New Image
Build the new container image. This may take a few minutes:

podman build -t llama-cart:v1 .

Clear your screen:
clear

Verify the image is there:

podman images

Run the container:

podman run -d –name=llama-cart -p 8090:90 llama-cart:v1

Verify the container started:

podman ps

Verify the nginx.zip files you should see when you log in:

unzip -l nginx.zip

Verify the tar files you should see when you log in:

tar tf llama_cart.tar

Connect to the container:

podman exec -it llama-cart bash

Look for the /etc/nginx files first:

ls /etc/nginx

View the contents:

ls /usr/share/nginx/html

Check /tar_file/:

ls /tar_file/

Exit out of the container:
exit

Verify the website is available on port 8090 of the system using a web browser; copy the public IP address into a browser and add :8090 at the end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly