docker deploy a simple hello world html website Edit

Murugan Andezuthu Dharmaratnam | 10 January 2022 | 1469

in this article, we will create a simple hello world index.html page that displays hello world and deploy it to a docker container. we will start with creating a simple index.html file with content <h1> hello world </h1>, ideally a minimal HTML page which displays hello world. Once the index.html page has been created we will create a docker image and then run the application in a docker.

Lets begin

Step 1: Lets create the index.html file

<h1>hello world</h1>

Step 2: create docker file.
Create file named Dockerfile and put it in the same folder as index.html

FROM nginx:1.21-alpine
COPY . /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Step 3: create docker image

-t is used to specify the tag and value

. this will create the docker image . I am using docker desktop installed on my laptop
docker build -t html-hello-world:v1 .

Step 4: run docker image

-p is used to binds port 80 of the container to TCP port 8080 of the host machine.

docker run -p 8080:80 html-hello-world:v1

Step 5: open application on the web browser

open your web browser and open http://localhost:8080 this will open up html page you have crated.