Use Podman to explore the properties and details of containers in your environment.
Run applications in a container using the following command:
podman run -d --name myapp nginx
Stop a running container using:
podman stop myapp
Start a stopped container using:
podman start myapp
List all containers, including running and stopped ones:
podman ps -a
Inspect detailed properties of a container:
podman inspect myapp
Remove a container using:
podman rm myapp
Access a running container interactively:
podman exec -it myapp /bin/bash
Save the state of a container as an image:
podman commit myapp myapp_image
Example 1: Save a basic container as an image. Example 2: Save with specific metadata or instructions.
- Container: A running instance of an image.
- Image: A template used to create containers.
List all available images:
podman images
View details about an image:
podman inspect myapp_image
Push an image to a remote registry:
podman push myapp_image docker://myregistry/myapp_image
Log into a container registry:
podman login docker.io
Tag an image for pushing to a registry:
podman tag myapp_image myregistry/myapp_image:v1
Remove a container image:
podman rmi myapp_image
Download an image from a registry:
podman pull nginx
Search for images on a registry:
podman search nginx
Mount a container image to access its contents:
podman mount myapp_image
A Containerfile
is the Podman equivalent of a Dockerfile
. Here's an example:
# Containerfile
FROM ubuntu:20.04
LABEL maintainer="[email protected]"
# Update and install necessary packages
RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy application code
COPY . /app
# Install dependencies
RUN pip3 install -r requirements.txt
# Expose the application port
EXPOSE 8080
# Command to run the application
CMD ["python3", "app.py"]
A Dockerfile
is used similarly to a Containerfile
and can be used interchangeably:
# Dockerfile
FROM nginx:latest
LABEL maintainer="[email protected]"
# Copy custom configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Set up content directory
WORKDIR /usr/share/nginx/html
# Copy website content
COPY . /usr/share/nginx/html
# Expose port 80
EXPOSE 80
# Start nginx
CMD ["nginx", "-g", "daemon off;"]
These examples illustrate how to define a base image, add application-specific dependencies, set up working directories, and define commands to execute when the container starts.
Demonstrate building an image using a Containerfile
or Dockerfile
:
podman build -t myapp_image .