Sikau

DevOps and deployment · Day 5 · about 35 min

Project: Serve the café site with nginx

An nginx image with your static files baked in.

The site needs a home

The café's static website lives in cafe/site. Package it into an nginx image so it can be deployed anywhere.

Building on an official image

The same steps apply to every service you'll ever containerise. Only the base image and the files you copy change, whether it's a static site, a Node API or a background worker.

This project is deliberately small so you can focus on the workflow rather than the content: write a Dockerfile, build an image, run a container from it, and check the result with your own eyes.

Official images like nginx:alpine already know how to run their software: the base image defines the start command, the port and the folder it serves files from. Your Dockerfile only adds what's specific to you — the site files. Two lines produce a complete, deployable web server.

FROM nginx:alpine
COPY site/ /usr/share/nginx/html/

Read an official image's page on Docker Hub: it documents the folders, ports and environment variables it expects.

The rest of this lesson

  • Build, run, checkexplain
  • Why package a static site?explain
  • Where does it come from?match
  • Ship the siteorder
  • cafe-webchallenge
  • Badge quizquiz
  • Unit 1 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 14 lessons of DevOps and deployment