Podman Examples

podman pull imagename

podman run imagename

Example:

podman pull hello-world

podman run hello-world

podman container ls

podman container ls -a

podman image ls

Let's try to launch Neo4J

Method 1

docker pull neo4j

docker run neo4j

Method 2

mkdir neo4j
cd neo4j
mkdir data
mkdir logs

Mac/Linux

podman run -it -d  --name myneo --publish=7474:7474 --publish=7687:7687 --volume=$PWD/data:/data --volume=$PWD/logs:/logs neo4j:latest

Windows

podman run -it -d  --name myneo --publish=7474:7474 --publish=7687:7687 -v data:/data -v logs:/logs neo4j:latest

Browser

http://localhost:7474 user: neo4j

pwd: neo4j

when it prompts change new pwd

To log into the Container

podman exec -it containername bash

To view the Log messages

podman logs containername

Custom Image

Create a file "Dockerfile"

# Use an official Ubuntu base image
FROM ubuntu:latest

# Install nginx
RUN apt-get update && apt-get install -y nginx

# Expose port 80
EXPOSE 80

# Run nginx
CMD ["nginx", "-g", "daemon off;"]

Build an image

podman build -t gc-nginx-image .

Run the container using above image

podman run --name my-web-app -d -p 8080:80 gc-nginx-image

Open browser and navigate to http://localhost:8080

Python Example

main.py


def add(x, y):
    return x + y

def subtract(x, y):
    return x - y

def multiply(x, y):
    return x * y

def divide(x, y):
    if y == 0:
        return "Error! Division by zero."
    return x / y

if __name__ == "__main__":
    print(add(1, 2))
    print(subtract(1, 2))
    print(multiply(1, 2))
    print(divide(1, 2))

Dockerfile

FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY main.py .

CMD ["python", "./main.py"]

requirements.txt

faker

Build (default it uses Dockerfile, but can customized with -f parameter)

podman build -t mycalc .
podman build -t mycalc -f pathtoDockerfile

Run

podman run --name gccalc mycalc

Last updated