Deploying a website using Docker- Nginx

What is Docker?
As per Wikipedia …
Docker is an open-source project that automates the deployment of software applications inside containers by providing an additional layer of abstraction and automation of OS-level virtualization on linux.

Below are the steps given below how to deploy a static website using nginx and linux server.

step 1: Install Docker in both server and the local machine. You can install for linux, windows and Mac Osx from the given link.
https://docs.docker.com/install/

Step 2: Make sure that you have your HTML files already in directory.

Step 3: Create a file with the name Dockerfile inside the directory with the following text

 
   FROM nginx:alpine
   COPY . /usr/share/nginx/html
 

Step 4: we will Build the Docker Image for the nginx Server for static page. make sure to add your username in case you are using Docker Desktop.In my case its girishsahu008

 
  docker build -t girishsahu008/webserver-image:v1
 

Step 5: Confirm that the Docker Image has been created successfully using the following command

 
  docker image
 

You will get a response like this.

Step 6: Run the docker image
docker run -d -p 80:80 girishsahu008/webserver-image:v1

Step 7: Check the installation using browser
http://localhost

Step 8: Login to your docker – Hub account in terminal. You can use any docker Hub.


 docker login
 username:girishsahu008
 password: ********
 Login succeeded

Step 7: Push the image to your docker hub account


 docker push girshsahu008/webserver-image:v1

Step 8: Login to your server using SSH.
Step 9: pull the docker image in server

 
  docker pull girshsahu008/webserver-image:v1
 

Step 10: Run the docker in server

 
  docker run -d -p 80:80 girishsahu008/webserver-image:v1
 

That’s it your code is deployed and running fine. You can use kubernetes to manage the docker container. I will update it in the next tutorial.

1 thought on “Deploying a website using Docker- Nginx

  1. Hi, techtutorial.online

    I’ve been visiting your website a few times and decided to give you some positive feedback because I find it very useful. Well done.

    I was wondering if you as someone with experience of creating a useful website could help me out with my new site by giving some feedback about what I could improve?

    You can find my site by searching for “casino gorilla” in Google (it’s the gorilla themed online casino comparison).

    I would appreciate if you could check it out quickly and tell me what you think.

    casinogorilla.com

    Thank you for help and I wish you a great week!

Leave a Reply

Your email address will not be published. Required fields are marked *

RSS
Follow by Email
Facebook
Twitter