Chapter 6: Docker Images and Containers
6.10 Lab — Dockerfile for badge API hello
Lab
Containerise the hello API from earlier Git chapters.
- Ensure the app has a health or root route you can curl.
- Write a Dockerfile (
FROM/COPY/RUN/CMD/EXPOSE). - Add
.dockerignoreexcluding.env,.git, dependency caches. docker build -t badge-api-hello:0.1 .docker run -d --name badge-api -p 8080:8080 badge-api-hello:0.1curlthe published host port; save the status code in your notes.docker logs badge-apianddocker execa simple command (ls/pwd).docker stopanddocker rmthe container. Keep the image for the next chapter if you like.
Practice task
List four Dockerfile instructions you used and one mistake each can cause if miswritten (wrong FROM, missing COPY, RUN without needed files, CMD vs shell form confusion).
Thodkyaat sangaycha tar
- Containers box the app; VMs (EC2) are learned in depth in the AWS course — do not mix the stories.
- Image = template; container = running instance; Dockerfile builds layered images.
- Daily commands:
build,run,ps,logs,exec,stop/rm. -p host:containerpublishes published ports;EXPOSEalone does not open the host door.- Publish only needed ports; keep secrets out of image layers with
.dockerignore.
Samajla ka? Nasel tar lab (6.10) sodun `curl` green yeiparyant build-run kara – `-p` aani app bind `0.0.0.0` donhi check kara. Aata pudhe jaauya Docker volumes, networks aani Compose kade.