10

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

 3 years ago
source link: https://dev.to/nipun214/deploying-a-static-website-in-a-container-and-ship-it-any-anywhere-4b68
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Cover image for Deploying a Static Website In a Container and  Ship it any Anywhere
Nipun Parekh

Posted on Oct 27

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 modeExit 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 modeExit 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 modeExit 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 modeExit 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 modeExit 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:

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/


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK