Skip to content

Docker Container Exercise

This exercise confirms your Docker setup and shows you how to:

  • pull a public Ubuntu image and show the pull output,
  • build a tiny custom image (Ubuntu + Python),
  • run a container that prints a one-line Python message.

Time: 15–25 minutes Deliverables: 3–4 screenshots (Docker version/hello-world, pull output, image build, container run)

Step 1 — Verify Docker works

Run the basic checks:

bash
docker --version
docker run hello-world

You should see a version string and the “Hello from Docker!” message. If not, revisit the Docker Desktop installation steps.

Deliverable A: Screenshot showing docker --version and the successful hello-world output.

Step 2 — Pull a base Ubuntu image (show the pull result)

Pull a versioned Ubuntu image and list your local images:

bash
docker pull iitrabhi/fenics_notebook:latest
docker images

Capture the layer download logs and the image listing with iitrabhi/fenics_notebook:latest. This reinforces the “image vs container” idea discussed earlier.

Deliverable B: Screenshot of docker pull output and docker images showing iitrabhi/fenics_notebook:latest.

Step 3 — Build a minimal custom image (Ubuntu + Python + one line)

Create a folder (e.g., docker_hello) with two files:

hello.py

python
print("Hello from your Ubuntu + Python Docker container!")

Dockerfile

dockerfile
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y python3
WORKDIR /app
COPY hello.py /app/hello.py
CMD ["python3", "hello.py"]

Build the image:

bash
docker build -t hello_docker .

This mirrors the simple “build a custom image and run a Python script” pattern from the custom images section.

Deliverable C: Screenshot of a successful docker build showing the tag hello_docker.

Step 4 — Run the container and capture output

Execute your new image:

bash
docker run --rm hello_docker

Expected output:

Hello from your Ubuntu + Python Docker container!

This confirms your Dockerfile installed Python, copied the script, and executed it as the default command.

Deliverable D: Screenshot of the container run showing the printed line.

(Optional) Step 5 — Share and pull your image

Practice sharing your image (either online or offline):

  • Docker Hub route: tag, login, and push; then pull on another system.
  • Offline route: docker save to a tar, transfer, then docker load on the other system.

Optional Deliverable: Screenshot of docker push/docker pull (and the run output after pulling).

Acceptance checklist (pass/fail)

  • Docker is installed and runs hello-world.
  • You successfully pulled ubuntu:22.04 and it appears in docker images.
  • Your custom image builds and the container prints the one-line message.
  • (Optional) You can push/pull your image (or save/load offline).

Why this matters (context)

This exercise uses a tiny Ubuntu + Python image, but the exact same concepts power our simulation containers (e.g., FEniCS). Containers give you consistent, reproducible environments across laptops, workstations, and servers — the core motivation introduced in the Docker chapter.

As you iterate, keep images versioned and your setup documented for reproducibility.