Day-6 Docker Zero To Hero Bangla Course (Module-6 Docker Containers With Nginx Web Server)

 


Prerequisites
Before we begin, make sure you have the following installed on your system:

    Git: For cloning the repository.
    Docker and Docker Compose: For running the application in containers.
    Nginx: As the web server to route requests.

Step 1: Clone the Repository

First, clone the repository using Git. This repository contains a .NET Core Web API starter project that you can use as a foundation for your application.

Open your terminal and run the following command:


git clone https://github.com/shawon100/backend-webapi-netcore-starter

This command will download the project files to a directory named backend-webapi-netcore-starter.
Step 2: Navigate to the Project Directory

After cloning the repository, navigate to the project directory:


cd backend-webapi-netcore-starter

Step 3: Run the Docker Containers

The project is pre-configured to run inside Docker containers. To start the containers, use Docker Compose. Run the following command:


docker-compose up -d

The -d flag runs the containers in the background (detached mode). Docker will now build the images and start the containers based on the configuration in the docker-compose.yml file.
Step 4: Install Nginx

Next, you'll install Nginx, which we'll use as a reverse proxy to route incoming requests to the appropriate service.

Run the following command to install Nginx:

sudo apt install nginx

sudo systemctl start nginx

sudo systemctl reload nginx

Step 5: Configure Nginx

With Nginx installed, you'll need to set up a configuration file to route traffic to your backend service. Suppose you have a configuration file named webapp.conf that you want to use.

Copy the webapp.conf file to the Nginx configuration directory:

sudo cp webapp.conf /etc/nginx/sites-enabled/

This places the configuration file in the sites-enabled directory, making it active.


Step 6: Test the Nginx Configuration

Before applying the changes, it's a good idea to test the Nginx configuration for any syntax errors:

bash

sudo nginx -t

If the configuration is correct, you should see a message indicating that the test was successful.


Step 7: Reload Nginx

Finally, apply the new configuration by reloading Nginx:

sudo systemctl reload nginx

Finally add the host entry in hosts file

sudo nano /etc/hosts

127.0.0.1     app.dotnetcore.com

Save it and go to web browser and type

app.dotnetcore.com/api/city

 

Video Tutorial

 


 


Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment