In this topic, we will discuss Docker setting in NGINX. NGINX is a popular lightweight web application that is used for developing server-side applications. It is an open-source web server that is developed to run on a variety of operating systems. Since Nginx is a popular web server for development, Docker has ensured that it has support for Nginx.
We will now see the various steps for getting the Docker container for Nginx up and running.
Step 1 − The first step is to pull the image from Docker Hub. When you log into Docker Hub, you will be able to search and see the image for Nginx as shown below. Just type in Nginx in the search box and click on the Nginx (official) link which comes up in the search results.
Step2 − You will see that the Docker pull command for nginx in the details of the repository in Docker Hub.
Step3− On the Docker Host, use the Docker pull command as shown above to download the latest nginx image from Docker Hub.
Step4 − Now lets run the nginx container via the following command.
sudo docker run –p 8080:80 –d nginx
We are exposing the port on the nginx server which is port 80 to the port 8080 on the Docker Host.
Once you run the command, you will get the following output if you browse to the URL http://dockerhost:8080. This shows that the nginx container is up and running.
Step 5 − Let’s look at another example where we can host a simple web page in our ngnix container. In our example, we will create a simple HelloWorld.html file and host it in our nginx container.
Lets first create an HTML file called HelloWorld.html
Lets add a simple line of Hello World in the HTML file.
Now run the following ducker command:-
sudo docker run –p 8080:80 –v “$PWD”:/usr/share/nginx/html:ro –d nginx
The following command need to be know−
- We are exposing the port on the nginx server which is port 80 to the port 8080 on the Docker Host.
- Next, we are attaching the volume on the container which is /usr/share/nginx/html to our present working directory.
Now if we browse to the URL http://dockerhost:8080/HelloWorld.html we will get the following output as expected −
Next Topic:-Click Here
Pingback: Docker - Building Files - Adglob Infosystem Pvt Ltd