top of page
tarati

A Podman Tutorial

Updated: Jul 5, 2022


In the past week, I completed my first course on Kubernetes (Scalable Microservices with Kubernetes). Following this, I felt that my understanding was still quite limited so I began another course titled "Cloud Foundation Natives". This is a more detailed course covering the history of cloud-native architecture, the types of cloud architecture (Monoliths and Microservices) and how to orchestrate containers in Kubernetes. I also started refreshing my knowledge of Git and the use of Github. Github has made many changes/improvements from the last time I used it which was three years ago.


In my UX internship, I was performing a user evaluation on the Podman desktop application (an alternative to Docker). While testing the application I realized I could apply my knowledge from the cloud foundation natives course. So I prepared a small tutorial on how to use Podman Desktop. If you are new to cloud architectures it would also help your understanding of the concepts.


Download and Installation


My first step was to download the podman application and there are two ways you can do this. You can proceed to the downloads section of their website and select your operating system. You could also visit their Github page and download a new release.


I downloaded the podman desktop flatpak from the website. There were no instructions on how to install it so I did the following on my Fedora operating system:

$ flatpak install podman-desktop-0.0.4.flatpak

Once you install the podman desktop, the welcome page will tell you there are no containers and you should run your first container - a hello-world container provided by the application. You will have to run the following command in your terminal:

$ podman run quay.io/podman/hello

If your application is working correctly, you should receive the following success message in your terminal "!... Hello Podman World ...!". You should also be able to view the container in the podman desktop application.


Trouble in paradise!

It was at this point, that I encountered my first issue. I could not see the containers I was starting in the terminal in the podman desktop software. Another Intern at RH, C, helped me with this problem. He asked to restart podman and run the following commands:

$ systemctl --user start podman.service
$ systemctl --user start podman.socket

After this, the podman desktop was working properly. The first sign was that under the section Preferences > Podman > Podman, the socket now had a location. This was empty before.


Using Podman


Now that I had a working application, I wanted to test it. As I said I am still new to containers and images, and I wanted to see how they worked in a real-world application.


The first thing I did was to pull out one of my old flask applications, which I simplified to one page/one python file. The full code can be found on my GitHub page.

</html>
<head> 
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>  
<h1>Welcome to my blog application!</h1>
<h3>Its fun here! Grab a drink!!</h1>
</body>

And the python file looks like this:

from flask import Flask, json, render_template
app = Flask(__name__)
import logging

@app.route("/")
def index():
    app.logger.info('load index successful')
    return render_template('login.html')

if __name__ == "__main__":
    logging.basicConfig(filename='app.log',level=logging.DEBUG)
    app.run(host='0.0.0.0')

All this code does is load the login page in the browser's local host, usually on port 5000.


I modified the docker file from my course, and ended up with something like this:

FROM python:3.8
LABEL maintainer="xx"

COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt

# view in browser on port 5000 - localhost:5000
EXPOSE 5000

# command to run on container start
CMD [ "python", "app.py" ]

Using the podman desktop, I navigated to Images > Build Image from Containerfile. Then I selected the above dockerfile and this was loaded into podman. By loading into podman, I mean that podman followed the instructions in the dockerfile and created an image out of it. So podman copied all the files in the directory, installed the python libraries listed in "requirements.txt", exposed the port 5000, and then run the command "python app.py".


My next step was to run the image, this created a container through which I can access my application. Because I ran this image, I could go to my browser to view the web page at the address "locahost:5000":



Registries


I wanted to try adding my docker account to podman. I proceeded to the section Preferences > Registries. I added the docker hub URL, my username and my password. Then I proceeded to the section Images > Pull Image From a Registry. I pulled my hello-world container from my docker hub account. It worked!

I also found out that if you just included your username in the Image to Pull text field, you won't need to add docker as a registry (since it's public I believe). My input was "owner/docker101tutorial", where owner was my docker username.


I wanted to push my blog app from my podman desktop to docker. But I could not find any option to do that within the user interface so I had to use the command line. It's probably something they would add later on. Or is there another reason for the registry? I'm not sure.

I used the following commands in my terminal:

# login to your docker account
$ podman login -u myusername -p mypassword docker.io/myusername/myimage
# get image id for podman image
$ podman images
$ podman push imageid docker://docker.io/myusername/myimage:1.0.0

Once I was done with the above tasks, I closed the podman desktop by using the following command:

pkill podman

Lessons


I found it really exciting to get Podman working. I found it especially intriguing to see one of my applications become an image and run as a container. When it comes to microservice architectures (which is the primary motivation behind using applications like podman). I haven't seen that in action yet but I'm looking forward to practising that too.

Also, Docker allows you to edit the code in your images and push new versions, I haven't tried/seen this functionality in Podman so I'm looking forward to trying that as well.


27 views0 comments

Recent Posts

See All

New Team!

Comments


bottom of page