Serving Static Page with Docker

qui

qui

Posted on June 19, 2024

Serving Static Page with Docker

Hello, I am qui! Today, we'll serve a static page with Docker.

Installing Docker

Install it with your package manager.

Debian/Ubuntu/Mint: https://docs.docker.com/engine/install/debian/#install-using-the-repository

Arch: sudo pacman -S docker docker-compose

Creating Dockerfile

Create Dockerfile. And enter to it.

We'll use nginx image. Add this: FROM nginx:alpine

We want to copy static site to /usr/share/nginx/html in container. Add this: COPY . /usr/share/nginx/html

Complete Dockerfile

FROM nginx:alpine
COPY . /usr/share/nginx/html
Enter fullscreen mode Exit fullscreen mode

Building Container

docker build -t <sitename>:latest .
Enter fullscreen mode Exit fullscreen mode

Run Container

If you want to run site in background, run this command: docker run -d -p 80:80 <sitename>:latest

If you don't want to run site in background, run this command: docker run -p 80:80 <sitename>:latest

If you are getting port errors, change 80:80 with 8080:80.

Credits

💖 💪 🙅 🚩
qui
qui

Posted on June 19, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Serving Static Page with Docker
webdev Serving Static Page with Docker

June 19, 2024