Proyek: Container Web Statis

Proyek ini mengemas situs katalog produk statis (site/index.html) ke dalam image nginx:1.29-alpine dan menjalankannya sebagai satu service Compose. Konfigurasi nginx.conf mengaktifkan gzip, cache 7 hari untuk aset statis, dan no-cache untuk index.html supaya pembaruan konten langsung terlihat.

Struktur Berkas #

BerkasPeran
site/index.htmlKonten situs (katalog produk)
nginx.confKonfigurasi server nginx (gaya conf.d)
DockerfileResep image multi-layer dengan validasi nginx -t
.dockerignoreMembatasi build context
compose.yamlDefinisi service web
README.mdDokumen ini

Menjalankan #

bash
docker compose up -d --build

Menguji #

bash
curl -I http://localhost:8080/
curl -s http://localhost:8080/ | grep "<title>"
curl -I -H "Accept-Encoding: gzip" http://localhost:8080/

Hasil yang diharapkan: respons 200 OK dengan header Server: nginx/1.29.4, Cache-Control: no-cache untuk index.html, Content-Encoding: gzip saat klien mengirim Accept-Encoding: gzip, dan halaman katalog tampil di browser pada http://localhost:8080/.

Membersihkan #

bash
docker compose down