DEV Community

qui
qui

Posted on

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

Top comments (1)

Collapse
 
lemi_1b38406cc232c4df2b64 profile image
Lemi

thanks :D