DEV Community

Andrea Bertoloni
Andrea Bertoloni

Posted on • Originally published at andreabertoloni.com

Define and serve an HTML page using a single Dockerfile

This is a quick and easy way to write an HTML page directly in the same Dockerfile where you define the Nginx server.

Use case:
I needed a very basic placeholder page for a project before it was actually put online.
Since I use Coolify, which allows you to use a Dockerfile as an application's source, I could easily achieve the goal by simply editing the file directly within the dashboard and hitting "Deploy".

Below is the complete Dockerfile setup:

FROM nginx:alpine # Create the HTML file RUN echo '<!DOCTYPE html>\ <html>\ <head>\ <title>My new project</title>\ </head>\ <body>\ <p>Lorem ipsum</p>\ </body>\ </html>' > /usr/share/nginx/html/index.html # Expose port 80 EXPOSE 80 # Run nginx in foreground CMD ["nginx", "-g", "daemon off;"] 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)