×

Html & Html5

The World's best Software Development Study Portal



How to Dockerize Html Website through Nginx Server


Create a HTML FILe in visual code
After that create a Docker File with name - Dockerfile(Base Image consist Dependcies Like JVM or App CLI etc.)
Write below commands inside Dockerfile
FROM nginx:alpine (Base Image-Web Server to run File)
COPY . /usr/share/nginx/html/ (Directory of nginx where data will be stored)
(Start your docker server)
Now the Build Command-:
docker build -t webserver-image:v1 .
Now we have to Run Docker Container
docker run -d -p 8080:80 webserver-image:v1 (-d detach, -p port)
GO to browser write - localhost:8080


How to Dockerize Html Website through Apache2 Server


Create a HTML FILe in visual code
After that create a Docker File with name - Dockerfile(Base Image consist Dependcies Like JVM or App CLI etc.)
Write below commands inside Dockerfile
FROM httpd:2.4
COPY . /usr/local/apache2/htdocs
EXPOSE 80
Now the Build Command-:
docker build -t apache-html-site .
Now we have to Run Docker Container
docker run -d -p 8084:80 apache-html-site
GO to browser write - localhost:8084






---------------------------------------------------------------------------------------------------------------------------

Pull Docker Image
docker pull nginx
So lets this image nginx 1.23 as container

docker run nginx:1.23

Open new terminal
write-
docker ps

We should see one container we just run Run docker image in background without blocking terminals-:
docker run -d nginx:1.23
And check with
docker ps
docker logs f8c246a78222(container ID)
- [ ] docker run nginx:1.22-alpine(if image not available locally then it will go to docker hub then pull the image)
Expose the Ports
If we try to access the ports
localhost:80 (nothing is available)
To accès that container we needs to bind it
First we will stop it
docker stop container ID
Lets create new container and do the port binding
docker run -d -p 9000:80 nginx:1.23 (-d running in background mode detached mode)(-p 9000:80 this port expose to localhost)
http://localhost:9000/ (open It in browser )
——————————————————————
Start n stop containers
docker ps -a(this give u list of start n stop containers)
Docker start container id
Docker stop container id
reset command to clear terminal in Mac
Give name to container
docker run --name parveen -d -p 9000:80 nginx:1.23
docker logs parveen
Create our own docker image for application.
Create a server.js file inside src folder
——————————————
const express = require ("express")
const app = express();
const port = process.env.PORT || 3000
app.get("/",(req,res)=>{
res.send("Hello to ITC")
});
app.listen(port,()=>{
console.log(`Server is runung on port no ${port}`);
})
—————————————
Now create Dockerfile inside src
FROM node:19-alpine
COPY package.json /app/
COPY / /app/
WORKDIR /app
RUN npm install
CMD ["node", "server.js"]








CSS 3 training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute