FILE: materi-20.module

Docker dan Containerization

Container vs VM. Image, container, registry. Dockerfile dan docker-compose.

RUNTIME: 28m LEVEL: intermediate STATUS: ACTIVE
APP DB REDIS QUEUE CONTAINERS DOCKER ENGINE HOST OS (LINUX)

1. Apa Itu Container

Lightweight virtualization. Bundle aplikasi plus dependency. Berbeda dengan VM: shared kernel, lebih cepat, lebih hemat resource. Docker bikin container mainstream sejak 2013.

2. Image vs Container

Image: blueprint, immutable. Container: instance dari image, mutable. Bisa run banyak container dari image sama. Image disimpan di registry (Docker Hub, AWS ECR, GHCR).

3. Dockerfile

File text yang define cara build image. FROM (base image). RUN (execute command). COPY (copy file). ENV (env var). EXPOSE (port). CMD (default command). Docker build bikin image dari Dockerfile.

4. Docker Compose

Define multi-container application di YAML. docker-compose.yml. Up dan down semua service sekaligus. Local development jadi mudah. Production pakai Kubernetes (lihat materi 21).

5. Best Practices

Multi-stage build untuk smaller image. Tidak run as root. Pakai base image official. Pin version (jangan latest). Layer caching untuk speed. Security scan dengan Trivy.

Practical Mission

  1. Install Docker dan run hello-world
  2. Build aplikasi sederhana dengan Dockerfile
  3. Setup PostgreSQL plus app dengan Compose
  4. Push image ke Docker Hub
  5. Pelajari security scanning dengan Trivy

Recap Module