
Podman is an open-source container management tool that enables you to develop, manage, and run OCI containers without a background daemon process. Its daemonless design enhances security and reduces resource usage.
This article explains installing Podman on Ubuntu 22.04 and performing essential container operations to manage containerized applications.
Prerequisites
Before you begin:
Have an Ubuntu 22.04 server.
Create a Container Registry to store your Podman container images. This article uses Vultr Container Registry as an example, but the commands can be adapted to any registry by switching to the appropriate registry-specific variables.
Access the server using SSH as a non-root user with sudo privileges.
Install Podman
Podman is available in the default Ubuntu 22.04 package repositories. Follow the steps below to install Podman using the APT package manager:
Update the server's package index.
console$ sudo apt update
Install Podman.
console$ sudo apt install podman -y
View the installed Podman version on your server.
console$ podman --version
Your output should be similar to the one below.
podman version 3.4.4
Manage the Podman System Service
Podman uses two system services: podman
for managing containers through the CLI, and podman.socket
for remote API access via systemd. podman.socket
enables remote management and integration with development tools. Follow the steps below to manage and enable Podman services on your server.
Enable the service to automatically start at system boot.
console$ sudo systemctl enable podman.socket
Start the service.
console$ sudo systemctl start podman.socket
Stop the service.
console$ sudo systemctl stop podman.socket
Restart the service.
console$ sudo systemctl restart podman.socket
View the service status and verify that it's running.
console$ sudo systemctl status podman.socket
Output:
● podman.socket - Podman API Socket Loaded: loaded (/usr/lib/systemd/system/podman.socket; enabled; preset: enabled) Active: active (listening) since Mon 2024-08-26 12:07:01 UTC; 37s ago Triggers: ● podman.service Docs: man:podman-system-service(1) Listen: /run/podman/podman.sock (Stream) CGroup: /system.slice/podman.socket
Deploy Containerized Applications using Podman
Podman uses image sources defined in the /etc/containers/registries.conf
file to pull container images. Follow the steps below to deploy an HTTP server using the Nginx container image from Docker Hub.
Pull the Nginx container image from Docker Hub.
console$ podman pull docker.io/nginx:alpine
Output:
Trying to pull docker.io/library/nginx:alpine... //... Writing manifest to image destination 1ae23480369fa4139f6dec668d7a5a941b56ea174e9cf75e09771988fe621c95
List all container images available on the server.
console$ podman images
Verify that the Nginx container image is available in your output.
REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/nginx alpine 1ae23480369f 6 weeks ago 45.1 MB
Run a new containerized application using the Nginx image.
console$ podman run -d --name nginx-server -p 9090:80 docker.io/nginx:alpine
List all running Podman container processes.
console$ podman ps
Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 20628c4b7d0f docker.io/library/nginx:alpine nginx -g daemon o... 4 seconds ago Up 4 seconds 0.0.0.0:9090->80/tcp nginx-server
Test access to the container using the host port
9090
.console$ curl http://localhost:9090
Output:
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> //.....
Log in to Vultr Container Registry
Podman supports custom registries like the Vultr Container Registry for building and storing container images. Follow the steps below to create a Python FastAPI application, build a container image, and push it to your Vultr Container Registry.
Access your Vultr Container Registry's management panel to view the registry's username and API key credentials.
Create a new environment variable to store your Vultr Container Registry name.
console$ export VULTR_CONTAINER_REGISTRY_NAME=<enter the Vultr Container Registry name>
Create another environment variable to store the registry username.
console$ export VULTR_CONTAINER_REGISTRY_USERNAME=<enter the Vultr Container Registry username>
Create a environment variable to store the registry's API key.
console$ export VULTR_CONTAINER_REGISTRY_API_KEY=<enter the Vultr Container Registry API key>
Log in to your Vultr Container Registry using the environment variable values.
console$ podman login sjc.vultrcr.com/$VULTR_CONTAINER_REGISTRY_NAME -u $VULTR_CONTAINER_REGISTRY_USERNAME -p $VULTR_CONTAINER_REGISTRY_API_KEY
Replace
sjc.vultrcr.com
with the URL of the region where your VCR is hosted.Output:
Login Succeeded!
Create a new Python application file
app.py
.console$ nano app.py
Add the following contents to the file.
pythonfrom fastapi import FastAPI, Response import uvicorn app = FastAPI() @app.get("/") def hello(): return Response(content="Hello from Vultr", media_type="text/plain") if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=5000)
Save and close the file.
The above FastAPI application initializes a new web server on port
5000
that displays aHello from Vultr
message when accessed.Create a new
Dockerfile
configuration.console$ nano Dockerfile
Add the following contents to the file.
dockerfileFROM python:3.12-slim WORKDIR /app COPY app.py /app RUN pip install fastapi uvicorn EXPOSE 5000 CMD ["python", "app.py"]
Save and close the file.
The above
Dockerfile
sets up a Python 3.12 environment, installsfastapi
anduvicorn
, and starts a web server on port5000
using the Python application fileapp.py
.Build the container image with all files in your working directory.
console$ podman build -t python-fastapi-app .
Output:
//... Successfully tagged localhost/python-fastapi-app:latest 8f00b7a023da93ce714c41ab817be66913385f8c8583b4c38e59a35e53af0037
Tag the container image with your Vultr Container Registry's name.
console$ podman tag python-fastapi-app sjc.vultrcr.com/$VULTR_CONTAINER_REGISTRY_NAME/python-fastapi-app:v1
Replace
sjc.vultrcr.com
with the URL of the region where your VCR is hosted.List all container images on your server and verify that the tagged image is available.
console$ podman images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE sjc.vultrcr.com/demo/python-fastapi-app v1 8f00b7a023da 30 seconds ago 217 MB localhost/python-fastapi-app latest 8f00b7a023da 30 seconds ago 217 MB docker.io/library/nginx alpine 1ae23480369f 6 weeks ago 45.1 MB docker.io/library/python 3.12-slim 8d6f9eba56c9 11 days ago 135 MB
Push the image to your Vultr Container Registry.
console$ podman push sjc.vultrcr.com/$VULTR_CONTAINER_REGISTRY_NAME/python-fastapi-app:v1
Replace
sjc.vultrcr.com
with the URL of the region where your VCR is hosted.Output:
//... Writing manifest to image destination
Deploy a new containerized application using your Vultr Container Registry image.
console$ podman run -d --name demo-app -p 5000:5000 sjc.vultrcr.com/$VULTR_CONTAINER_REGISTRY_NAME/python-fastapi-app:v1
Test access to the application using Curl on the host port
5000
.console$ curl http://localhost:5000
Output:
Hello from Vultr
Conclusion
In this article, you installed Podman on Ubuntu 22.04 and deployed containerized applications. Podman allows you to build, store, and run containers on your server efficiently.
No comments yet.