- Docker - Working of Kubernetes
- Docker - Kubernetes Architecture
- Docker - Continuous Integration
- Docker - Compose
- Docker - Logging
- Docker - Cloud
- Docker - Setting ASP.Net
- Docker - Toolbox
- Docker - Setting NGINX
- Docker - Setting MongoDB
- Docker - Setting Node.js
- Docker - Networking
- Docker - Storage
- Docker - Container Linking
- Docker - Instruction Commands
- Building a Web Server Docker File
- Docker - Private Registries
- Docker - Managing Ports
- Docker - Public Repositories
- Docker - Building Files
- Docker - File
- Docker - Containers & Shells
- Docker - Configuring
- Docker - Container & Hosts
- Docker - Architecture
- Docker - Working With Containers
- Docker - Containers
- Docker - Images
- Docker - Hub
- Docker - Installation
- Docker - Installing Docker on Linux
- Docker - Overview
- Docker - Home
Docker Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Docker - Setting NGINX
NGINX is a popular pghtweight web apppcation that is used for developing server-side apppcations. 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 cpck on the nginx (official) pnk which comes up in the search results.
Step 2 − You will see that the Docker pull command for nginx in the details of the repository in Docker Hub.
Step 3 − On the Docker Host, use the Docker pull command as shown above to download the latest nginx image from Docker Hub.
Step 4 − Now let’s 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.
Let’s first create an HTML file called HelloWorld.html
Let’s add a simple pne of Hello World in the HTML file.
Let’s then run the following Docker command.
sudo docker run –p 8080:80 –v “$PWD”:/usr/share/nginx/html:ro –d nginx
The following points need to be noted about the above command −
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. This is where our HelloWorld.html file is stored.
Now if we browse to the URL http://dockerhost:8080/HelloWorld.html we will get the following output as expected −
Advertisements