Build Nginx-HTML Docker Image using Dockerfile

0 / 80
NGINX-HTML docker image


Creating Static HTML docker image using Dockerfile

 



In this article we will learn how to create a simple static html docker image using Dockerfile. We will pull nginx latest image from docker hub and copy our sample index.html page to the container.

To learn the basics & architecture of docker follow this article.

To learn how to install docker follow this article.

We have a html application which displays simple index page with contents –
1
This is the index page of html-app displayed from nginx container!

Below is the sample index.html page which we will copy to the container –
cat index.html
1
This is the index page of html-app displayed from nginx container!

Below is the Dockerfile which we will use –
cat Dockerfile
1
FROM nginx:latest

1
COPY ./index.html /usr/share/nginx/html/index.html

Now to build image locally run docker build command –
1
# docker ps

1
# docker build -t localhost/nginx-html-app:v1 .

1
# docker images
 

nginx-docker image

Creating Nginx docker image

 

To test image/container run it –

1
# docker run -it -d --name nginx-html-app -p 8080:80 localhost/nginx-html-app:v1

1
# docker ps

To ensure that our HTML page is being delivered appropriately, open your browser and visit to http://localhost:8080.
1
# curl localhost:8080
 

List docker images  

We can also access it on IP of host on which docker is running.
I hope you now have the knowledge you need to learn more about creating a Dockerfile, deploy html application using docker and perhaps you can utilize it in a project in the future. Follow us on


Facebook & LinkedIn  



Comments

comments


***Linux, Cloud & Devops Architect & Technical Content Writer*** I am a Linux Enthusiast and Supporter/Promoter of Open Source Technology with over 12+ years of experience in Linux, Cloud and Devops. I am A Technical Content writer for various sites like : Hostbread & Golibrary

Related Posts