Simple Static Site on Nginx on Docker

Here's about the simplest static site on Docker you can make.

Deployment Target

Docker can go a lot of places. So many places allow you to deploy with Docker. So, can you run your app in a Docker environment? Oh yeah, sure.

Create Static Site

There are so many static site generators. But what's the simplest static site? An index.html file. Here's one:

<!DOCTYPE html>
<html>
  <body>
    <h1>Custom static thing, served from nginx</h1>
  </body>
</html>

Create Dockerfile

Now all you need is the docker container configuration, in the form of a Dockerfile. Here's one:

FROM nginx:latest

COPY ./static /usr/share/nginx/html

This is a custom container based on the official nginx official. Put your index.html in a static/ directory. This will copy all of those static/ files into /usr/share/nginx/html, which is the default www root in the official nginx image filesystem.

Simplest static site with nginx on Docker.

Build and Run Site

Build container:

docker build -t customweb .

Run container:

docker run -it --rm -d -p 8080:80 --name web2 customweb

See static site:

xdg-open localhost:8080

Oh, such beauty! Well, this is a very simple foundation for us to build from: static site on Dockerfile.

Want the code? Clone jaketrent/ohai-docker-nginx.