How to set up NGINX in Docker

Last updated on May 27 2022
Raigiri Patil

Table of Contents

How to set up NGINX in Docker

Docker – Setting NGINX

NGINX is a popular lightweight web application that is employed 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’ll now see the various steps for getting the Docker container for nginx up and running.

Step 1 − The primary 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 within the search box and click on the nginx (official) link which comes up within the search results.

Page 1 Image 1 56
nginx

Step 2 − You will see that the Docker pull command for nginx within the details of the repository in Docker Hub.

Page 2 Image 2 50
pull

Step 3 − On the Docker Host, use the Docker pull command as shown above to download the latest nginx image from Docker Hub.

Page 2 Image 3 25
nginx image

Step 4 − Now let’s run the nginx container via the subsequent 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.

Page 2 Image 4 6
server

Once you run the command, you will get the subsequent output if you browse to the URL http://dockerhost:8080. This shows that the nginx container is up and running.

Page 3 Image 5 18
welcome

Step 5 − Let’s look at another example where we can host a simple web page in our ngnix container. In our example, we’ll create a simple HelloWorld.html file and host it in our nginx container.

Let’s primary create an HTML file called HelloWorld.html

Page 3 Image 6 7
hello world

Let’s add a simple line of Hello World within the HTML file.

Page 3 Image 7 1
simple line

Let’s then run the subsequent Docker command.

sudo docker run –p 8080:80 –v    “$PWD”:/usr/share/nginx/html:ro –d nginx

The subsequent 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.
Page 4 Image 8 1
volume

Now if we browse to the URL http://dockerhost:8080/HelloWorld.html we’ll get the subsequent output as expected −

Page 4 Image 9 2
output

So, this brings us to the end of blog. This Tecklearn ‘How to set up NGINX in Docker’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Docker and build a career in DevOps domain, then check out our interactive, Containerization using Docker Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/containerization-using-docker/

Containerization using Docker Training

About the Course

Tecklearn has specially designed this Containerization using Docker Training Course to advance your skills for a successful career in this domain. his Docker training online course will help you learn Docker containerization, running Docker containers, Docker image creation, Dockerfile, Docker orchestration, security best practices and more through hands-on projects and case studies. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Docker.

Why Should you take Containerization using Docker Training?

  • Average salary of Docker Expert is $110k – Indeed.com
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.
  • Intuit, PayPal, Splunk, Uber & many other MNC’s worldwide use Docker across industries

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Containerization using Docker – Part 1

  • Introduction to Docker
  • Understanding Docker Lifecycle
  • Docker Architecture
  • Components of Docker Ecosystem
  • Common Docker Operations
  • Committing changes in a Container
  • Hands On

Containerization using Docker – Part 2

  • Building Custom Docker Images
  • Docker Image
  • Introduction to Docker Swarm
  • Deploying a 2-Node Cluster using Docker Swarm
  • Hands on

 

0 responses on "How to set up NGINX in Docker"

Leave a Message

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