Hosting a static content in Nginx docker

Search for a command to run...

No comments yet. Be the first to comment.
Introduction Argo Workflows is an open-source workflow orchestration tool for Kubernetes. In this tutorial, we will walk through the steps to install Argo Workflows on a Kubernetes cluster and access its server UI. Step 1: Check Current Context Befor...

The Azure CLI is a powerful tool for managing and automating tasks in Azure. To use the Azure CLI, you need to log in to your Azure account. In this blog, we will go over the different methods you can use to log in to Azure using the Azure CLI. Log i...

Connecting to an Azure VM from windows can be a bit tricky and you may get errors like WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions for ' ' are too open, It is required that your private key files are NOT accessible by others This private key w...

A methodology where all the configurational and/or infrastructure codes are set up in a separate single repository is known as GitOps. This suits tools like Ansible, Terraform and Kubernetes, where they do require separate files for their configurati...

Straight to the point, there are tons of things to ask in JS, but these are a few of them which can be a quick refresher. Event loop, Single-threaded programming language - Explain, Asynchronous and synchronous, Promises and callbacks, "This" ke...

Peace to you all , Here is the Link to my previous blogs , Where I have posted about Docker, Containers and DevOps.
This is Day 4 of documenting my DevOps journey .
This blog focuses on Hosting a static content on Nginx in docker .
In the previous blog , we successfully ran an Nginx web server on docker ,if not just kindly copy paste the below code .
docker pull nginx
You can check whether the image has been pulled by ,
docker images

image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643035215829/12PoA81xI.png)
We also have a static website already ready in our previous blog , if not just kindly copy paste the below code
<h1> This is a sample Web App </h1>
and save it as an HTML file .
Now , We need to find where Nginx has its HTML files in them , in order to change those html file and replace it with our own .
Scrolling down on the Nginx image in docker hub , we can find the instructions on how to host a simple static content .
/some/content should refer to the path of our html file , we just built .
In my case , I have saved the file inside the users in C:, so my command would be ,
docker run --name webapp -d -p 80:80 -v /c/Users/name/dockersample:/usr/share/nginx/html nginx
Breaking down the above command ,
run —> To run an instance of the image mentioned ,
name —> To set name to the container ,
d —> To run the container in detached mode ( runs in the background and we can have the terminal back),
p —> To access ports in container from hosts ,
v —> Setting up the volume from host to container and
Finally the name of the image , here it is nginx.
Running the above command , displays an ID - which is the container ID.
Now we can check whether the container is running by a command ,
docker ps
or
in the docker desktop ,

We can find that the container is running successfully.
Once the container starts running , we can open a browser and check on localhost:80 .
!!! We successfully hosted a static content on Nginx and ran the container in docker!
Though it looks simple , Trust me , This is huge .
We pulled an image from Docker Hub ,
The image is known for hosting web applications , Nginx,
We had a static content and mounted it to Nginx image’s static web page and successfully ran it.
Okay . So hold on, stay with me as we get to know docker more and DevOps even more.
Okay Then , Will get back Tomorrow with more!
Peace be upon you!