Objective

Write Dockerfiles and build optimized container images.

Tools & Technologies

  • Dockerfile
  • docker build
  • docker tag

Key Commands

docker build -t myapp:1.0 .
docker tag myapp:1.0 registry/myapp:1.0
docker push registry/myapp:1.0
docker history myapp:1.0

Lab Steps

01
Dockerfile Basics

Write a Dockerfile with FROM, RUN, COPY, EXPOSE, CMD instructions.

02
Layer Caching

Understand layer caching and order instructions to maximize cache hits.

03
Multi-stage Builds

Use multi-stage builds to reduce final image size.

04
Push to Registry

Tag and push images to Docker Hub or a private registry.

Challenges Encountered

  • Large image sizes from not using .dockerignore
  • Cache invalidation from changing early layers

Key Takeaways

  • Use alpine-based images to minimize attack surface and size
  • Multi-stage builds can reduce image size by 80%+