/minginx

Minimalist nginx for the Raspberry Valley makerspace

Primary LanguageDockerfileMIT LicenseMIT

Mini nginx

We want to run small web apps on our Pi or development machines here at Raspberry Valley. So, Docker to the rescue. This repository defines a minimalist nginx image for serving sites. The image is as simple as possible, because most of our sites are static sites (generated by Mkdocs, Jekyll etc.).

So what were the key requirements? As small as possible, runs on PC and Raspberry Pi, serves mostly static web sites.

Building the image

You can download the image from our Docker Hub. As always, be carefull about using 3rd party images. For the paranoid then - you can build your own instead (after studying the content of the files and/or modifying it to your exact needs).

To build the image:

  • clone this repository and modify if needed
  • copy the appropriate Dockerfile from the subfolders provided in the repository to the root of the repository. For building on Raspberry Pi, copy from minginx-rpi, for your PC, copy from minginx
  • using PowerShell or similar, run the following:
docker build -t minginx .

Done.

Testing the image

To test the image, simply create a container using the below:

docker run --rm -p 8080:8080 -it minginx

You should see the index page content (the one and only page in the image included for testing).

Done.

Using the image

The scenario the image was built for was of course to serve pages from a static site on the host or maybe in a volume. For using a site created on the host, we will map the host folder to the container. Run something similar to this:

docker run --rm -p 8080:8080 -v your/site/directory:/usr/share/nginx/html minginx

Or on anything apart from Windows (Linux, PowerShell script, Raspberry Pi etc.), you can run this:

docker run --rm -p 8080:8080 -v ${pwd}:/usr/share/nginx/html minginx

Powershell Script

For Windows, you can launch the container using our PowerShell script (available in this repository). The idea is to launch a static site in the current directory from PowerShell without bothering about typing parameters. Just copy the script to a directory on the path and you're good to go.

You can of course create your own script. Here is the script we use as inspiration:

# Raspberry Valley Docker minimalist Nginx

Write-Host
"MiNginx - Raspberry Valley minimalist web server
=================================================
This script launches MiNginx to serve a site from your current directory

* Raspberry Valley Makerspace site: https://raspberry-valley.azurewebsites.net

Serving directory: ${pwd}
"

$command = "docker run --rm -p 8080:8080 -v ${pwd}:/usr/share/nginx/html raspberryvalley/minginx"
iex $command

Using the image - as a container with data

For sites which should be served, maybe for reference but don't change too much, you might want to roll your own image including the content. Here is a sample Dockerfile, which will allow you to use our image, include the site and run with no dependencies.

Sample Dockerfile:

# Sample dockerfile

FROM raspberryvalley/minginx

LABEL maintainer = Raspberry Valley <raspberryvalley@outlook.com>

# Copy your site into image (we use KB as a site directory/name: substitute for your own)
RUN mkdir kb
COPY /kb/ /usr/share/nginx/html/kb/

# end of Dockerfile

Once you have created your image, just launch (don't forget to expose the port)

About

Raspberry Valley is a maker community in Karlskrona, Sweden, sponsored by Dynapac. We run makerspaces every week, working with Raspberry Pis, Arduinos and other interesting hardware.

This repository is here to support our community of makers. A lot of our achievements are based and inspired by the community at large. We wish to pay back and share our experiences and lessons learned. Join us!

You can find our pages here: Raspberry Valley. You can also join us on Twitter or check Docker Hub for images of interest.

Links

Raspberry Valley makerspace links