Assignment 1: Containerize an app and push it to the registry
Goal: Take a small application, write a house-style Dockerfile for it, build a small and secure image, and push that image to the lab's private registry at 10.100.100.6 — then prove it runs from the registry copy.
Where: Any lab VM that has Docker installed (Docker was installed via get.docker.com). The private registry is registry:2 with htpasswd auth at 10.100.100.6. Get your registry username/password from your mentor.
Tasks
- Pick or write a tiny web app that listens on a port and serves an HTTP response (a "hello" web server in any language is fine — Node, Python, or Go). It must expose a
/healthendpoint returning HTTP 200. - Initialise a git repo for it (
git init) so you have a commit SHA to tag with. - Write a
.dockerignorethat excludes at least.git, build artifacts/dependencies (e.g.node_modules), logs, and any.env. - Write a multi-stage Dockerfile that follows every house convention:
- a pinned base image (specific tag, ideally a digest),
- a separate build stage and a slim runtime stage,
- a non-root runtime
USER, - an
EXPOSEfor the app port, - a
HEALTHCHECKthat curls/health, - a
CMDto start the app.
- Build the image with a sha-based tag:
10.100.100.6/<yourname>/<app>:sha-<shortsha>. - Run it locally and confirm:
docker run -d -p 8080:<port> ..., thencurl http://localhost:8080/healthreturns 200. Checkdocker logs. docker login 10.100.100.6, thendocker pushyour tagged image.- Remove the local image (
docker rmi),docker pullit back from10.100.100.6, run it again, and confirm/healthstill returns 200 — proving the registry copy works.
Deliverable
A short writeup (paste into your BookStack notes or a markdown file) containing: the app's Dockerfile, the .dockerignore, the exact build/login/push commands you ran with their tags, the docker images line showing your final image size, and the curl output from the registry-pulled container.
Acceptance criteria — you're done when:
- The app exposes a working
/healthendpoint returning HTTP 200. - A
.dockerignoreexists and excludes.git, dependencies/build output, logs, and.env. - The Dockerfile uses a multi-stage build with a slim runtime stage.
- The base image is pinned (specific tag or digest), not
latest. - The container runs as a non-root
USER(verify withdocker exec <c> whoami— notroot). - A
HEALTHCHECKis present anddocker psshows the container ashealthy. - The image is tagged
10.100.100.6/<yourname>/<app>:sha-<shortsha>(sha-based, nolatest). -
docker pushto10.100.100.6succeeded. - After
docker rmi+docker pullfrom the registry, the pulled container serves/healthwith HTTP 200.
Hints
- Re-read Chapter 5 section 3 if rebuilds feel slow — order matters for caching.
docker exec <container> whoamiis the quickest way to confirm you are non-root.docker psshows(healthy)next to the container once the HEALTHCHECK passes; if it isunhealthy, run the healthcheck command manually inside the container withdocker execto see the error.- If
docker pushis denied, you likely skippeddocker login 10.100.100.6or used the wrong namespace. - If
docker loginfails on TLS, ask your mentor whether the registry needs aninsecure-registriesentry in the Docker daemon config — do not guess. - Get the short SHA with
git rev-parse --short HEAD.
Blocked for >~30 min after re-reading the lessons? Bring what you've tried to your mentor.
No comments to display
No comments to display