Image alt

NGINX, being lightweight and free to use, is a popular choice as a web application load balancer and reverse proxy. However, like any tooling in the toolbelt of a DevOps engineer, it works best when dockerized (packaged and run inside a Docker container).

In this tutorial, we’ll take a look at a simple example of how to serve a static HTML site through a Docker container that runs NGINX.

Let’s start by creating our dummy website:

/static/index.html


<html lang="en">
<head><title>Hello, World</title></head>
<body>Hello, NGINX</body>
</html>

Then, let’s create the Dockerfile that will package our website and serve it through NGINX that will be running inside a Docker container:

/Dockerfile

FROM nginx:1.23.1-alpine
COPY ./static /usr/share/nginx/html

Now let’s try building our Docker container:

docker build -t website .

The last step is to launch our newly built Docker image:

docker run -p 8080:80 website

If you visit http://localhost:8080 in your browser now, you should see the static page that we created above.