Md Toy Blog



How to run a static html page in Docker.

NginX is an open source web server, and now also used as a reverse proxy and a Seabee caching and as well as a load balancer.

This was basically created to answer the C 10k problem which is network problem to provide access to a lot of nodes at the same time.

Copy all the files in the dockerfile directory to the specified folder in /usr/share/nginx/html

FROM nginx:alpine
COPY . /usr/share/nginx/html


now in the same directory as where we have our Dockerfile for this project, we need to create the file that we are going to serve (which is named by default index.html). So for convenience let's create a index.html:

<!doctype html>
    <h1>Welcome to NGiNX!</h1>


Now we build the deamon: with image that we will tag as nginx-app:

cd myDockerfileFolder
sudo docker build -t nginx-app .
# [sudo] password for g:
# Sending build context to Docker daemon   2.56kB
# Step 1/2 : FROM nginx:alpine
# alpine: Pulling from library/nginx
# cbdbe7a5bc2a: Pull complete
# c554c602ff32: Pull complete
# Digest: sha256:763e7f0188e378fef0c761854552c70bbd817555dc4de029681a2e972e25e30e
# Status: Downloaded newer image for nginx:alpine
#  ---> 89ec9da68213
# Step 2/2 : COPY . /usr/share/nginx/html
#  ---> 0379cd8611f4
# Successfully built 0379cd8611f4
# Successfully tagged nginx-app:latest


Then to run our deamon with a container that we name docker-ngx and listen to 9000 and pipe it to the standard nginx port 80 we do:

sudo docker run --name docker-ngx -p 9000:80 -d nginx-app
# 921b47d3537642b6cb40df180e3064f8adc8a80b34f5b91bfe18352552eb038d


When we make changes to our code, we need to stop the current container, remove it, then build again and run again.

sudo docker stop docker-ngx
# docker-ngx
sudo docker rm docker-ngx
# docker-ngx
sudo docker run --name docker-ngx -p 9000:80 -d nginx-app