DEV Community

Cover image for Deploying a Static Website In a Container and  Ship it any Anywhere
Nipun Parekh
Nipun Parekh

Posted on

Deploying a Static Website In a Container and Ship it any Anywhere

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:

  1. Creating Docker file
  2. Create an image of our static website with use of Docker file
  3. Push that image to Docker Hub
  4. Run that container on Server

Creating Docker File:

FROM nginx:latest
COPY . /usr/share/nginx/html
EXPOSE 80
CMD [“nginx”,”-g”,”daemon off;”]
Enter fullscreen mode Exit fullscreen mode

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>" .
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

So by use of this command your static website will be running with the use of Docker.

Demo of static site is hosted:
Alt Text

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)