Guide to setting up Docker Nginx to work with an Express and React application on a Windows

After finding tutorials about CSS, React, and Node, I realized none of them combined all three. My goal is to learn how to deploy react websites on my domain for testing purposes. However, the learning process has been overwhelming with the cascade of new information. Although I feel comfortable with CSS, JS, and React individually, I need guidance on how to bring it all together. Any recommendations or suggestions would be greatly appreciated as I continue on my learning journey.

Can anyone advise on the best order to learn these technologies in order to achieve my goal? I have dabbled in Windows PowerShell, completed some Node and Express tutorials, and even managed to run Nginx on Docker briefly. But now I find myself feeling stuck and unsure of my next steps.

Below are the video tutorials that I have watched:

Answer №1

To run multi container Docker applications, you can utilize a docker-compose.yml file which defines and runs the necessary services with a single command. Both Linux and Windows programs can be executed in Docker, creating lightweight virtual environments for your apps. Here is an illustration of the desired folder structure:

|--client  
     |--Dockerfile
     |--components
     |--index.js
|--server
     |--Dockerfile
     |--index.js
|--nginx
     |-- Dockerfile
     |--default.conf
|--docker.compose.yml

The Dockerfile for the react client:

FROM node:alpine as builder
WORKDIR '/app'
COPY ./package.json . /
RUN npm install
COPY . .
RUN npm run build

The Dockerfile for nginx:

FROM nginx 
COPY ./default.conf /etc/nginx/conf.d/default.conf

The default configuration default.conf for nginx:

upstream client {
    server client:3000;
}

upstream api {
    server api:5000;
}

server {
    listen 80;

    location / {
        proxy_pass  http://client;
    }
    location /sockjs-node {
        proxy_pass http://client;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }

    location /api {
        rewrite /api/(.*) /$1 break;
        proxy_pass  http://api;
    }
}

The Dockerfile for the node/express server:

FROM node:alpine
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
CMD [ "npm", "run", "start" ]

Your docker-compose.yml file allows flexibility to switch databases for your API. Building and running everything is achieved by executing docker-compose up --build from the project's main directory (where the docker-compose file is located).

version: '3'
services:
  nginx:
    restart: always
    build:
      dockerfile: Dockerfile
      context: ./nginx
    ports:
      - '80:80'
  mongo:
    container_name: mongo
    image: mongo
    ports:
      - '27017:27017'
  api:
    restart: always  
    build:
      dockerfile: Dockerfile
      context: ./server
    volumes: 
      - /app/node_modules
      - ./server:/app
    links:
      - mongo
    ports:
      - '5000:5000'
    depends_on:
      - mongo
  client:
    build:
      dockerfile: Dockerfile
      context: ./client
    volumes:
      - /app/node_modules
      - ./client:/app
    links:
      - api

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show the id value of the event triggered by eventclick

I am currently attempting to retrieve the id of the event so that I can remove it from the database. My approach involves using eventClick, where a dialog pops up when the user clicks an event prompting them to remove it. In order to proceed with this oper ...

Removing the displayed image chips from the database using reactjs

How can I remove an image chip displayed from the database? Here is the code for displaying images from the database: {user.isImageUploaded != null ? <div > <p> {user.isImageUploaded.map(item => { const datatypeV ...

When using Edge browser developer tools local override feature, changes made are not visible after closing the developer tools

Even though I am discussing the issue with the edge-browser, it also occurs in the chrome-browser Instructions to Replicate While many may know me as a developer, I have a passion for customization and unique fonts. One font that has caught my eye rec ...

Elements on the page are quivering as a result of the CSS animation

When a user clicks anywhere on a div, I have added a ripple effect to give it some interaction. However, there is an issue where the element shakes and becomes blurry when the page is in full screen mode until the ripple effect disappears. Below is the Ja ...

Troubleshooting partial content error while streaming MP4 with GridFS, NodeJS, and React

I have been working on my streaming project for a while now and everything seems to be going well, except for the fact that I am encountering a 206 partial content error when streaming large MP4 files. After conducting extensive research, it appears to be ...

Rotational transformation in CSS not displaying in Webkit / iPhone browsers, yet functioning properly in Chrome Devtools device toolbar

tl;dr: My CSS transform rotate is not rendering on Webkit / iPhone, but it works in Chrome Devtools device toolbar. Update: I've also opened a separate GitHub issue that is more concise and easier to read, without code excerpts, here. Giving some co ...

Is there a way to use Regex to strip the Authorization header from the logging output

After a recent discovery, I have come to realize that we are inadvertently logging the Authorization headers in our production log drain. Here is an example of what the output looks like: {"response":{"status":"rejected",&quo ...

Whenever I attempt to retrieve an element, the array mysteriously transforms into undefined

Understanding React's Context API In my current project, I am utilizing React's context API to efficiently pass collected data from my API, which is built using Node.js, Express, and MongoDB. One crucial aspect of this setup is the boards array, ...

Webpack attempts to duplicate files prior to compilation but I am anticipating the opposite outcome

I needed the copy plugin to run after compilation, which seemed like the logical order. However, I found myself having to compile using webpack twice every time in order to get the fresh version on production. It wasn't until later that I realized it ...

A large responsive bootstrap website filling only half the screen

I am currently in the process of developing a simple version of a Content Management System (CMS). I have created a page that offers an HTML template, allowing users to insert their own text and image uploads to display on another screen. The template fun ...

Unraveling the operations of Node.js in its http.createServer method

I can't wrap my head around createServer in Node.js. This specific part of the code is really giving me trouble. http.createServer((req, res) => { let viewUrl = getViewUrl(req.url); fs.readFile(viewUrl, (error, data) => { if (error) { ...

Having trouble with Updating the Records in NodeJs and Angular

As a beginner in Node.js with Angular, I have been working on a simple CRUD application. Adding, deleting, and viewing records works fine for me. However, I am facing issues with updating records. Whenever I make changes on the form and click the submit bu ...

React Calculator: Addressing the glitches with decimal points and equation calculations

I've successfully developed a calculator using React, but I'm stuck on two things: I need to prevent the user from inputting a second decimal point if they have already clicked it once I want the equation to use the last operator (e.g., 5 * - + ...

Sticky Bootstrap Navbar

I am trying to incorporate a Bootstrap 4 navbar into a div with a background image. My goal is for the navbar to become sticky at the top, resize, and change color as the user scrolls down the page. However, I've noticed that when I place the navbar w ...

Developing a Node.js API using Express and MySQL involves utilizing the WHERE IN clause and binding parameters with multiple comma-separated values

Having a URL structure as shown below, where multiple comma-separated values can be added to the URL: localhost:4001/api/v1/users/search?title=mr,dr This is my query implementation: router.get('/search?', function(req, res, next) { var ...

A sleek and modern fixed navigation bar in Bootstrap 4 featuring two elegantly stacked rows, with a striking brand image perfectly centered

I need help creating a Bootstrap 4 fixed navigation bar with 2 rows. The first row should have a centered brand image like the one on (with the image size changing after scrolling down), and the second row should contain the navigation menu. Thank you i ...

The final DOM is not loading properly when using Jest and React Testing Library during page initialization

I'm currently working on testing my React application with Jest and React Testing Library. During this process, I am attempting to verify that the login page displays a specific message once it has fully loaded. Upon initial loading of the login page, ...

GZIP compression causes a total page layout malfunction

Thank you for taking the time to visit. I've been attempting to tackle this issue on my own, but it seems to be a bit overwhelming for me once again. THE SCENARIO... I have my website live on a shared hosting platform. As I delved into compressing my ...

Using AngularJS to incorporate personalized font icons

Looking to create a custom font icon library similar to "Font Awesome" for my AngularJS project, as using fonts instead of images is more versatile across devices. Is there a way to achieve this? I have generated a font in .ttf and .svg formats with my ...

The API fetching component is experiencing issues in a production environment following deployment via Vercel

I am facing a peculiar issue with my API setup. When I run the app on localhost:3000, everything works perfectly and the activity is rendered as expected. However, once I deploy the app and test it live, the activity no longer renders. I am using Vercel&ap ...