🛠️ Lab 2 — Container Lifecycle and Inspection Toolkit (50 pts)

Goal: Practice the full lifecycle of running, inspecting, entering, and cleaning up containers using four official Docker Hub images, and document what you find in a reference table you can reuse later in this course. Steps:

  1. Confirm Docker Desktop (or your local Docker engine from Week 01) is running: docker --version.
  2. Pull and run each of the following official images, giving each a memorable --name:
  3. Run docker ps to confirm which containers are running, then docker ps -a to see all four, including any that exited. Take a screenshot or copy the terminal output.
  4. Apply a resource constraint by removing and re-running one container with limits, for example: docker run -d --name my-nginx-limited -m 256m --cpus="0.5" -p 8081:80 nginx. Confirm it started with docker ps.
  5. Test port mapping by opening http://localhost:8080 (and http://localhost:8081) in your browser to confirm nginx responds. Record whether each one loaded successfully.
  6. Use docker exec -it my-nginx bash (or sh if bash isn't available in that image) to open an interactive shell inside the running nginx container. Run ls /usr/share/nginx/html to view the default web root, then exit to leave the shell without stopping the container.
  7. Check logs for at least two containers with docker logs my-redis and docker logs my-nginx.
  8. Practice lifecycle commands: docker stop my-busybox, then docker start my-busybox, then docker restart my-redis.
  9. Intentionally test the "ephemeral data" misconception: exec into my-nginx and create a test file (touch /tmp/my-note.txt), exit, then run docker rm -f my-nginx and start a brand-new container from the same image (docker run -d --name my-nginx-2 -p 8082:80 nginx). Exec into the new container and confirm /tmp/my-note.txt does NOT exist. Write one sentence explaining why.
  10. Clean up: stop and remove all containers you created (docker rm -f <name> for each, or docker container prune for stopped ones).
  11. Build a Markdown or table-based summary document with one row per image (nginx, redis, python, busybox) covering: default exposed port (if any), whether -it or -d was more appropriate for that image, one thing you found when you explored its filesystem via docker exec, and any resource limits you tested.

Deliverables: Submit your summary table (as an uploaded file or pasted text) plus your terminal output/screenshots showing docker ps -a, the docker exec session, the logs output, and the ephemeral-data test from Step 9, along with your one-sentence explanation of why the file disappeared.