How to Configure NGINX in Docker Compose?
Last Updated :
26 Apr, 2024
In modern web development, the act of containerization has acquired widespread reception because of its proficiency, portability, and adaptability benefits, containerization allows developers to package applications and their conditions into lightweight, isolated containers, ensuring consistency across various conditions and working on deployment processes.
Inside the domain of containerization, Docker has emerged as a main platform, providing tools and services to smooth out the turn of events, sending, and the board of containerized applications, one such device is Docker Compose, which empowers the definition and orchestration of multi-container Docker applications through a basic YAML configuration file.
The combination of Docker Compose and Nginx offers developers a vigorous solution for deploying and managing containerized web servers. By utilizing Docker compose capacities for defining application services and Nginx's ability as a reverse proxy, developers can make versatile, strong, and effectively deployable web applications.
We'll delve into the complexities of arranging containerized web servers utilizing Docker Compose and Nginx. We'll cover fundamental ideas, give step-by-step guidance, and deal with functional guides to assist readers with getting a handle on the essentials and outfit the maximum capacity of these innovations, whether you're a carefully prepared designer or beginning with containerization, this article intends to furnish you with the knowledge and tools expected to improve and smooth out your web development work process.
Primary Terminologies
Nginx
Definition: Nginx is a high-performance, open-source web server and converse proxy server. It is known for its productivity, versatility, and capacity to deal with high volumes of simultaneous associations.
Explanation: Nginx is many times utilized as a web server to serve static substance and as a converse intermediary to course incoming requests to backend servers. With regards to Docker compose, Nginx can be designed as a converse intermediary to circulate incoming web traffic to various services inside a Docker environment.
Containerization
Definition: Containerization is the most common way of typifying an application and its conditions into a lightweight, portable container that can run reliably across various conditions.
Explanation: Containerization allows developers to package their applications alongside every one of the essential conditions, libraries, and design files into a single container, this container can then be sent on any platform that supports containerization, ensuring a steady way of behaving and decreasing similarity issues.
Reverse Proxy
Definition: A reverse proxy is a server that sits between client devices and backend servers. It gets demands from clients and advances them to the proper backend server, then, at that point, returns the reaction to the client.
Explanation: With regards to Nginx and Docker compose, Nginx can be designed as an opposite intermediary to course incoming web requests to various services running inside Docker containers. This takes into account load balancing, traffic routing, and SSL termination, among different advantages.
YAML
Definition: YAML (YAML Ain't Markup Language) is a human readable serialization format that is usually utilized for configuration files.
Explanation: YAML is utilized in Docker Compose configuration files to define the construction of multi-container applications. It gives a simple and easy-to-read syntax structure for determining the services, organizations, volumes, and different settings expected for an application to run in a Docker environment.
Step-by-Step Process
Step 1: Launch an Instance
- Now go to AWS Console login with your credentials or create New Account
- Go to EC2 dashboard and launch an EC2 Instance

- Now connect with terminal

Step 2: Install Docker
- In this step we are installing docker because to run a docker compose we need to install docker. Install docker by using following command
sudo yum -y install docker

- Now start and enable docker by using following command
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
- we can status of the docker by using sudo systemctl status docker command

- After completion of docker installation. Now we need to change permissions to docker.sock, By using following commands we can change permission to docker.sock
sudo usermod -aG docker ec2-user
sudo chmod 666 /var/run/docker.sock

Step 3: Install docker-compose
- Now install docker-compose by using following command
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- We can check docker-compose version by using following command
docker-compose --version

Step 4: Create Working Directory
- Now create a working directory by using following command
mkdir <filename>
- Now move to created directory by using following command
cd <filename>

Step-5: Create Docker Compose configuration
- Before going to create a docker-compose configuration file Create the directory that will hold your HTML files. Create by using following
mkdir src

- Write something for your first page by using following command
echo "Hello, GeeksforGeeks" > src/index.html

- Now create a docker-compose file by using following command
- sudo vi docker-compose.yml
- Inside docker-compose file write below script
version: "3"
services:
client:
image: nginx
ports:
- 8000:80
volumes:
- ./src:/usr/share/nginx/html

Step 6: Now run the Docker-compose up
- Now run the docker-compose up -d command to run the docker-compose file
docker-compose up -d or docker-compose --detach

Step 7: Verify
- Now go to EC2 dashboard and copy public IP Address of ec2 instance and browse it along with port 8000

Conclusion
By utilizing Docker Compose, developers can define and coordinate multi-container applications easily. The YAML-based configuration improves on the arrangement process and considers the consistent integration of different services expected by current web applications.
Nginx serves in as an important part in containerized conditions, acting as a high performance web server and reverse proxy. Its capacity to deal with incoming web traffic, distribute requests to backend services, and perform progressed routing and load balancing makes on it an optimal decision for orchestrating web traffic inside Docker containers.
As you proceed with your excursion with Docker compose and Nginx, make sure to remain inquisitive, try different things with various configurations, and embrace the continuous learning experience. With the right tools and knowledge available to you, you can raise your web development work process and assemble state of the art applications that satisfy the needs of the present digital scene.
In conclusion, Docker Compose and Nginx address a unique team in the realm of containerized web servers, empowering developers to release the maximum capacity of containerization and change how web applications are deployed and managed.
Similar Reads
How to Install and Configure Docker in Ubuntu? Docker is a platform and service-based product that uses OS-level virtualization to deliver software in packages known as containers. Containers are separated from one another and bundle their software, libraries, and configuration files. Docker is written in the Go language. Docker can be installed
6 min read
How to Install PHP Composer Inside a Docker Container PHP Composer is a dependency manager for PHP allowing developers to manage project dependencies, libraries, and packages efficiently. Installing Composer inside a Docker container provides a consistent environment across different systems, ensuring that the application behaves the same way on every
6 min read
How to Configure Memory Limits in Docker Compose: A Comprehensive Guide When you run Docker-contained applications, there is a need for the proper management of resource allocation to allow for stability and performance. Docker Compose is a tool for defining and running multi-container Docker applications. Through it, one can define resource constraints, such as memory
6 min read
How to Setup Jenkins in Docker Container? Setting up of Jenkins in a docker container provides the facility of streamlining the CI/CD with scalability and consistency. It also helps for attaching the worker nodes as slaves and run the build jobs over their. In this article, we will guide you through the process of deploying jenkins in a Doc
6 min read
What does Flag do in Docker Compose? Docker Compose is a tool that is mostly used to create and execute multi-container apps. It is the secret to opening the door to a more simplified and effective deployment and development process.What is Docker Compose?Docker Compose makes it simple to manage services, networks, and volumes in a sin
5 min read
Docker Compose YAML Explained: A Deep Dive into Configuration Containerization is one of the recent revolutionary ways to develop, deploy, and manage applications in the dynamic software development arena. Docker remains in its premier position as one of the de facto platforms in containerization that helps developers package applications with their dependenci
9 min read
How to Use Docker Compose With Jenkins In the fast-paced world of software development, it is mainly ensured by automation of repetition and task persistence. This is where Docker Compose and Jenkins come into play. Docker Compose is a tool for defining and running multi-container Docker applications. On the other hand, Jenkins is a wide
8 min read
How do you Mount Volume in Docker Compose File ? Docker is a containerization tool that encapsulates the application along with its dependencies and runtime into compact units called docker containers. On the other hand, Docker Compose is a service through which multiple Docker container applications can be managed easily. In this guide I will fir
4 min read
How to Use AWS CLI in Docker Container ? The AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. Integrating AWS CLI within a Docker container can significantly streamline workflows, especially for development and deployment processes that rely on cloud infrastruct
4 min read
How to Install Docker on CentOS? Quick Preview to Install Docker on CentOS:Installation of Docker on CentOS:Open CentOS Terminal.Execute the command yum update in the Root Menu.Run the command yum install -y yum-utils device-mapper-persistent-data lvm2.Execute the command yum-config-manager --add-repo https://download.docker.com/li
4 min read