How to Install Podman on Ubuntu 24.04

Updated on November 21, 2023
How to Install Podman on Ubuntu 24.04 header image

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:

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.

  1. Update the server's package index.

    console
    $ sudo apt update
    
  2. Install Podman.

    console
    $ sudo apt install podman -y
    
  3. 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.

  1. Enable the Podman service to automatically start at system boot.

    console
    $ sudo systemctl enable podman.socket
    
  2. Start the Podman service.

    console
    $ sudo systemctl start podman.socket
    
  3. Stop the Podman service.

    console
    $ sudo systemctl stop podman.socket
    
  4. Restart the Podman service.

    console
    $ sudo systemctl restart podman.socket
    
  5. 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.

  1. 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
  2. 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
  3. Run a new containerized application using the Nginx image.

    console
    $ sudo podman run -d --name nginx-server -p 9090:80 docker.io/nginx:alpine
    
  4. 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
  5. 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.

  1. Access your Vultr Container Registry's management panel to view the registry's username and API key credentials.

  2. Create a new environment variable to store your Vultr Container Registry name.

    console
    $ export VULTR_CONTAINER_REGISTRY_NAME=<enter the Vultr Container Registry name>
    
  3. Create another environment variable to store the registry username.

    console
    $ export VULTR_CONTAINER_REGISTRY_USERNAME=<enter the Vultr Container Registry username>
    
  4. 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>
    
  5. 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
  6. Create a new Python application file app.py.

    console
    $ sudo nano app.py
    
  7. Add the following contents to the file.

    python
    from 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 a Hello from Vultr message when accessed.

  8. Create a new Dockerfile configuration.

    console
    $ sudo nano Dockerfile
    
  9. Add the following contents to the file.

    dockerfile
    FROM 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, installs fastapi and uvicorn, and starts a web server on port 5000 using the Python application file app.py.

  10. 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
  11. 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
    
  12. 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
  13. 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
  14. 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
    
  15. 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.