What is Docker?
Ans: Docker is a set of platform as a service products that use virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files.
Steps that we are going to perform:
- Creating Docker file
- Create an image of our static website with use of Docker file
- Push that image to Docker Hub
- Run that container on Server
Creating Docker File:
FROM nginx:latest
COPY . /usr/share/nginx/html
EXPOSE 80
CMD [“nginx”,”-g”,”daemon off;”]
FROM — is where we are pulling our official image from nginx is an official image provided by Docker
COPY — is taking our all file from out local directory were are working in and moves it into the /usr/share/nginx/html directory(of NGINX) in our container.
EXPOSE- is a instruction letting the container know we are exposing the port 80 (TCP)
CMD- provide defaults for an executing container
Create an image of our static website with use of Docker file:
For that we have to execute command and that is:
docker build -t "<name of image you have to put>" .
This command means :
-t = Tag
"" = your image name
. = it will take dockerfile form present location.
So in my case, I am going to give image name as nipun2020/docker-community-rajkot
command will be for me :)
docker build -t nipun2020/docker-community-rajkot .
Push that image to Docker Hub
To push our image in docker hub for that we will use this command
docker push
in my case it will be ->
docker push nipun2020/docker-community-rajkot
Run that container on Server
Login into your server and make sure docker is installed on your server.
and just hit this command and your container will be running on your server.
docker run -p 80:80 nipun2020/docker-community-rajkot
So by use of this command your static website will be running with the use of Docker.
Demo of static site is hosted:
Thank you for reading this blog, hope you learned some new thing.
If, you have any doubt you can contact me on LinkedIn
LinkedIn: https://www.linkedin.com/in/nipun-parekh-6006a0152/
Top comments (0)