Notes & Cheatsheet: “Dockerizing an App – CKA Series #2”



This content originally appeared on DEV Community and was authored by Darshan Vasani

Notes & Cheatsheet: “Dockerizing an App – CKA Series #2”

🎯 Goal of the video

  • Show, from scratch, how to containerise (“dockerise”) a sample Node.js app, push it to Docker Hub and run it anywhere.
  • Lays foundation for later CKA topics (pods, images, registries, best-practices).

1  Prerequisites & Sandbox options

  • Local install: Docker Desktop (Mac, Windows, Linux).
  • Zero-install alternative: Play-with-Docker (Docker-provided 4-hour sandbox).
  labs.play-with-docker.com  →  Start  →  Add new instance

2  Clone sample project

# create workspace
mkdir day02_code && cd day02_code      

# pull sample “getting-started” todo app
git clone https://github.com/docker/getting-started.git
cd getting-started/app        # contains package.json, src/, etc.

3  Write the Dockerfile

# ─── 1. Base image ───────────────────────────────────────────────
FROM node:18-alpine                              # tiny Linux + Node.js

# ─── 2. Set workdir inside container ─────────────────────────────
WORKDIR /app

# ─── 3. Copy source code into image ──────────────────────────────
COPY . .

# ─── 4. Install prod deps only ───────────────────────────────────
RUN yarn install --production

# ─── 5. Expose port app listens on ───────────────────────────────
EXPOSE 3000

# ─── 6. Container start-up command ───────────────────────────────
CMD ["node","src/index.js"]

🧩 Flow diagram

Host FS ─► docker build
          │
          ▼
      Dockerfile  ──►  Layered Image (base → code → deps) ──► Registry

4  Build image locally

docker build -t day02-todo:latest .

Image is now visible via: docker images or Docker-Desktop > Images.

5  Push to Docker Hub

# 1. create repo on hub:  /test-repo  (public is fine)

# 2. tag local image for hub
docker tag day02-todo:latest  /test-repo:latest

# 3. login and push
docker login
docker push /test-repo:latest

6  Run the container anywhere

# pull (if on fresh machine)
docker pull /test-repo:latest

# run detached, publish host:3000 → container:3000
docker run -d -p 3000:3000 --name todoapp /test-repo:latest

Open http://localhost:3000 📝✅.

7  Troubleshoot inside the container

# open an interactive shell (Alpine uses sh)
docker exec -it todoapp sh
# inspect files, logs, env, etc.

8  Key Docker CLI quick-ref

Task Command
List images docker images
List running containers docker ps
Stop & remove docker stop && docker rm
Remove image docker rmi
Clean dangling layers docker system prune

9  Next-step teaser 🐣

Image weighs 217 MB—too big for a tiny todo app!

Hint for next video: multi-stage builds and other best practices shrink it dramatically.

💡 Takeaways

  • Dockerfile = deterministic recipe → identical runtime everywhere.
  • Layered cache speeds builds & transfers.
  • Registry push/pull workflow mirrors real CI/CD pipelines.
  • Knowing basic docker build/run/exec is a must before jumping into Kubernetes objects (pods, deployments, etc.). 🎓


This content originally appeared on DEV Community and was authored by Darshan Vasani