Container Lab 1 - SS67/project-docs GitHub Wiki
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.
Objective: Learn to pull, run, and inspect a standard containerised web server.
-
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).
-
Command:
-
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:8080flag maps host port 8080 to container port 8080.
-
Command:
-
Verify the Web Server: Open a browser on your host and navigate to
localhost:8080to see the default Apache test page. -
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
-
Command:
Objective: Automate image creation using a Containerfile and share it to a remote registry like Quay.io.
-
Prepare the Context: Create a directory to hold your build files.
-
Commands:
mkdir mybuild && cd mybuildecho "<h1>Hello from Podman Lab</h1>" > index.html
-
Commands:
-
Create the Containerfile: Define the recipe for your new image.
- Create a file named
Containerfilewith this content:FROM ubi8/httpd-24 COPY index.html /var/www/html/index.html
- Create a file named
-
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.
-
Command:
-
Registry Authentication: Log in to your remote registry account.
-
Command:
podman login quay.io -
Note: This creates an
auth.jsonfile in a temporary location to store your credentials securely for the session.
-
Command:
-
Push the Image: Upload your image so it can be pulled from other VMs.
-
Command:
podman push quay.io/your_username/myimage:1.0
-
Command:
-
Image Cleanup: After pushing, delete the local copy of your image using
podman rmi --force quay.io/your_username/myimage:1.0and 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 unshareandpodman image mountto view the image’s root filesystem directly on your VM host.