Maybe you need a web server for a simple static site. For instance, to test out the
<script type="module">. Perform a Lighthouse Audit. Or preview your HTML page through you phone.
But it can be tedious to install, configure & fire up a web server on your local machine.
Today I'm going to show you how you can save some precious time & serve your static assets with this simple Docker Compose configuration.
1 — Go back to your base directory
$ cd ~/
2 — Create the working directory
$ mkdir docker-nginx-demo
3 — Go into that directory
$ cd docker-nginx-demo
4 — Create the Docker & Docker Compose configuration
$ touch docker-compose.yaml
5 — Create the directory that will hold your HTML files
$ mkdir src
6 — Write something for your first page
$ echo "Hello world!" > src/index.html
7 — Edit your Docker Compose configuration file
$ vim docker-compose.yaml
version: "3" services: client: image: nginx ports: - 8000:80 volumes: - ./src:/usr/share/nginx/html
8 — Start the server
$ docker-compose up --detach
9 — Open your page
$ chromium http://localhost:8000
10 — Enjoy!
That's it! You can enjoy your HTML page with your favorite browser at http://localhost:8000.