# Hosting a static content in Nginx docker

# Introduction

Peace to you all , Here is the Link to my previous [blogs](https://shajith.hashnode.dev/) , 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 .

# Getting Started

In the previous [blog](https://shajith.hashnode.dev/docker-images-and-docker-containers) , we successfully ran an Nginx web server on docker ,if not just kindly copy paste the below code .

```jsx
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/v1643035294323/mYv7HUAgw.png)
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 .

# Exploring the Nginx web server

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](https://hub.docker.com/_/nginx) , we can find the instructions on how to host a simple static content .


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643035384851/Mg2assW1N.png)
/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 ,

```jsx
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 ,

```jsx
docker ps
```

or 

in the docker desktop ,


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643035416680/ajPdZeu33.png)

We can find that the container is running successfully.

# Opening in browser

Once the container starts running , we can open a browser and check on [localhost:80](http://localhost:80) .


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643035448330/2iGS0nMvh.png)
!!! We successfully hosted a static content on Nginx and ran the container in docker!

Though it looks simple , Trust me , This is huge .

# What have we done

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.

# See you Tomorrow

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!
