Skip to content

Container Lab 1

Sujay Singh edited this page Aug 3, 2026 · 1 revision

Based on Chapter 2 of the sources, here is the detailed guide for Lab 1: CLI & Image Management. This lab focuses on the fundamental lifecycle of containers and the process of building and sharing images.

Part 1: Basic CLI & Image Practice

Objective: Learn to pull, run, and inspect a standard containerised web server.

  1. Pull the Image: Start by pulling the Red Hat Universal Base Image (UBI) for Apache.
    • Command: podman pull ubi8/httpd-24
    • Insight: If you don't specify a registry, Podman may prompt you to choose one (e.g., registry.access.redhat.com).
  2. Launch the Container: Run the container in detached mode (-d) so it runs in the background, and map the ports.
    • Command: podman run -d -p 8080:8080 --name myapp ubi8/httpd-24
    • Explanation: The -p 8080:8080 flag maps host port 8080 to container port 8080.
  3. Verify the Web Server: Open a browser on your host and navigate to localhost:8080 to see the default Apache test page.
  4. Inspect for the IP Address: Use the inspect tool to view the container's internal metadata.
    • Command: podman inspect myapp
    • Advanced Tip: To find just the IP address from the massive JSON output, use a format filter: podman inspect --format '{{ .NetworkSettings.IPAddress }}' myapp

Part 2: Advanced Challenge – Build and Ship

Objective: Automate image creation using a Containerfile and share it to a remote registry like Quay.io.

  1. Prepare the Context: Create a directory to hold your build files.
    • Commands: mkdir mybuild && cd mybuild echo "<h1>Hello from Podman Lab</h1>" > index.html
  2. Create the Containerfile: Define the recipe for your new image.
    • Create a file named Containerfile with this content:
      FROM ubi8/httpd-24
      COPY index.html /var/www/html/index.html
  3. Build the Image: Tag the image with your registry username during the build.
    • Command: podman build -t quay.io/your_username/myimage:1.0 .
    • Insight: The . at the end tells Podman to use the current directory as the build context.
  4. Registry Authentication: Log in to your remote registry account.
    • Command: podman login quay.io
    • Note: This creates an auth.json file in a temporary location to store your credentials securely for the session.
  5. Push the Image: Upload your image so it can be pulled from other VMs.
    • Command: podman push quay.io/your_username/myimage:1.0

Reinforcement Challenges

  • Image Cleanup: After pushing, delete the local copy of your image using podman rmi --force quay.io/your_username/myimage:1.0 and then pull it back down to prove it exists in the registry.
  • The Mount Shortcut: Instead of running the container to see your files, use podman unshare and podman image mount to view the image’s root filesystem directly on your VM host.

Clone this wiki locally