DEV Community

Cover image for Quick Web Server with Nginx on Docker Compose

Nginx Docker Compose Quick Web Server with Nginx on Docker Compose

aminnairi profile image Amin ・1 min read

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"

        image: nginx
            - 8000:80
            - ./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.

No need for any Apache, NGINX, MAMP, XAMPP, LAMP or any web server installed on your machine. Only Docker & Docker Compose are needed!

Discussion (3)

Editor guide
andymedjlp profile image
Andy Medlicott

Thanks! Simple and effective! :-)

tomfern profile image
Tomas Fernandez

Nice post! I think the Dockerfile contents are missing in the example.

aminnairi profile image
Amin Author

Yes it's a mistake. At first I though I would need a Dockerfile but not at all. That's what made me happy about that! But I'll correct the article. Thanks for pointing that out!