How to Install Podman on Ubuntu 24.04
Introduction
Podman is an open-source container management tool that lets you develop, manage, and run Open Container Initiative (OCI) containers without a background daemon process. Podman enhances the security of containerized applications and reduces resource usage due to its daemonless design.
This article explains how to install Podman on Ubuntu 24.04 and perform essential container operations to manage containerized applications.
Prerequisites
Before you begin:
- Deploy a Ubuntu 24.04 instance on Vultr.
- Create a Vultr Container Registry to store your Podman container images.
- Access the server using SSH as a non-root user with sudo privileges.
- Update the server.
Install Podman
Podman is available in the default package repositories on Ubuntu 24.04. Follow the steps below to install Podman using the APT package manager on your server.
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$ sudo podman --version
Your output should be similar to the one below.
podman version 4.9.3
Manage the Podman System Service
Podman uses two system services for managing containers, podman
CLI and podman.socket
. podman
is the command-line interface that enables direct interaction with Podman, enabling users to manage resources such as containers, images, and pods. podman.socket
is a systemd
socket file that provides remote API access to Podman, which is useful for remote management and integration with container development tools. You can use podman.socket
to run Podman as a system service. Follow the steps below to manage the Podman system service and enable the application to run on your server.
Enable the Podman service to automatically start at system boot.
console$ sudo systemctl enable podman.socket
Start the Podman service.
console$ sudo systemctl start podman.socket
Stop the Podman service.
console$ sudo systemctl stop podman.socket
Restart the Podman service.
console$ sudo systemctl restart podman.socket
View the Podman 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 a variety of image sources to find and pull container image using registries in the /etc/containers/registries.conf
file. Follow the steps below to deploy an HTTP server application based on the Nginx container image from Docker Hub.
Pull the Nginx container image from Docker Hub.
console$ sudo 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$ sudo 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$ sudo podman run -d --name nginx-server -p 9090:80 docker.io/nginx:alpine
List all running Podman container processes.
console$ sudo 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 such as the Vultr Container Registry to build and store container images. Follow the steps below to create a Python application using FastAPI, build a new application image and push the containerized application image 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$ sudo podman login https://sjc.vultrcr.com/$VULTR_CONTAINER_REGISTRY_NAME -u $VULTR_CONTAINER_REGISTRY_USERNAME -p $VULTR_CONTAINER_REGISTRY_API_KEY
Output:
Login Succeeded
Create a new Python application file
app.py
.console$ sudo 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$ sudo nano Dockerfile
Add the following contents to the file.
dockerfileFROM python:3.12-slim WORKDIR /app COPY . /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$ sudo 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$ sudo podman tag python-fastapi-app sjc.vultrcr.com/$VULTR_CONTAINER_REGISTRY_NAME/python-fastapi-app:v1
List all container images on your server and verify that the tagged image is available.
console$ sudo 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$ sudo podman push sjc.vultrcr.com/$VULTR_CONTAINER_REGISTRY_NAME/python-fastapi-app:v1
Output:
//... Writing manifest to image destination
Deploy a new containerized application using your Vultr Container Registry image.
console$ sudo 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
You have installed Podman on an Ubuntu 24.04 server and deployed containerized applications. Podman enables you to build, store, and run containerized applications on your server. For more information and configuration options, please visit the Podman documentation.