Dockerizing a React application with Nodejs Postgres and NginX | dev and prod | step by step

Поделиться
HTML-код
  • Опубликовано: 30 июл 2024
  • In this tutorial we are going to create a multicontainer application which will be running in docker containers.
    We will create both the development and production version of Docker files.
    Locally we will use a docker-compose file that will run the backend, front-end, postgres and nginx proxy. And you will be able to start the whole construction with one command.
    For front-end we're going to use React, for backend we are going to use Node.Js
    and we are going to use Postgres to store the data in the database.
    We are going to use Nginx for 2 purposes, we will use it as a router in front-of our front-end and Node.js express server, and also we will use Nginx as a HTTP server which will serve our builded React front-end code.
    You can find the final source code here: gitlab.com/codeching/docker-m...
    In my next tutorial, we will deploy the whole solution on Kubernetes, so stay with me, it will be very exciting :)
    00:00 - Intro
    01:26 - Arcthitecture
    02:15 - Setup project basics
    03:25 - Creating the back-end Node.js application
    09:12 - Creating the front-end React application
    17:56 - Creating the dev env Docker files
    20:18 - Creating the docker-compose file
    27:15 - Creating the prod env Docker files - build images and push them to Docker hub
    31:32 - Summary
    ------------------------------
    My name is László Leber
    Webpage: lebersoftware.hu
    Facebook: Codeching-11...
    Twitter: / codeching
    Instagram: / laszlo_leber
  • НаукаНаука

Комментарии • 68

  • @codeching
    @codeching  6 месяцев назад +1

    If you really liked this video, now you can say thank you with the 'super like' button as well, you can find it under my video! Thank you for watching this :)!

  • @AKASH-sw9bs
    @AKASH-sw9bs Год назад +11

    Your tutorial is good for those who already know docker and nginx but dont know how to glue all these things up in production.
    Good job. Carry on

  • @Zentamusic
    @Zentamusic 2 года назад +1

    Thank you so much. I was having some trouble configuring nginx proxy requests to the backend in a personal project of mine but looks like this tutorial clears it up. Thank you

    • @codeching
      @codeching  2 года назад +2

      Very good to hear if it helped for you :) You're welcome!

  • @user-kw9cu
    @user-kw9cu Год назад +1

    excatly what i was looking for

  • @rauldeandrade
    @rauldeandrade 3 года назад +2

    Great video. I really appreciate the content. Great job!

    • @codeching
      @codeching  3 года назад

      Thank you for your response!

  • @bagabaya5956
    @bagabaya5956 10 месяцев назад

    Thx so much for your work!

  • @Ray47nl
    @Ray47nl Год назад +14

    I really love your tutorial!
    I had some problems setting up the client.
    I am using react 18 and i had to change some things in App.js to make it work:
    import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
    And also:

    • @codeching
      @codeching  Год назад +4

      Thank you that you shared it! It will be useful for others.

  • @colbyberger1881
    @colbyberger1881 8 месяцев назад +1

    Under rated video. This was really helpful!

  • @edisonraulbarreirozambrano4519
    @edisonraulbarreirozambrano4519 Год назад +1

    Great video, Sir.
    Thanks for all the shared info.

    • @codeching
      @codeching  11 месяцев назад

      Thank you! :)

  • @swagz6440
    @swagz6440 Год назад +1

    Is there different configuration doing this tutorial with vue.js because i followed up to this point and I am getting bad gateway. My backend is working but my frontend doesnt seem to expose the port 5173

  • @tyeasir
    @tyeasir 2 года назад +1

    this was very helpful, thank you

  • @Play_Streams
    @Play_Streams 2 года назад +1

    Great videos, very well explained concepts.

  • @unzi876
    @unzi876 Год назад +1

    awesome explanation. thank you💯💯

  • @kag3670
    @kag3670 3 года назад +1

    Thank you for your tutorial, I have a question, I have cloned your project and trying to start it, I am using windows and my hot reload is not working, when I make changes and save it reflects inside the container, but no reload happens, not on the front nor on the server.

    • @codeching
      @codeching  3 года назад +1

      You're welcome! Yes, I updated the source code of docker compose file. I added CHOKIDAR_USEPOLLING environment variable with true value to the client. In case of React application (Created with CRA) it's the way to restart the application inside the container when we save the code in dev environment. However, the volume is also important, but it's already set up in this project. In case of node js it should be working because the Docker file set up start script "nodemon" already.

  • @roopamchakrawarty682
    @roopamchakrawarty682 3 года назад +1

    Thank you..Very helpful Video....Can you make more videos like this.please

    • @codeching
      @codeching  3 года назад +1

      Thank you so much! I will do my best in the future too :)

  • @Ramesh140789
    @Ramesh140789 Год назад

    I'm getting 404 from nginx ..if I reload the page

  • @AugustoMontagna
    @AugustoMontagna Год назад +1

    Thanks for the video! Great explanation. I feel Im missing something though. When you present the architecture, there is an nginx for routing, I dont see the production version. Is it the same as for local? regards

    • @codeching
      @codeching  Год назад +1

      Yes, in prod we have 2 nginx config, one for routing and one for HTTP server to serve the HTTP content. I'm speaking about it from 27:16

  • @jaylenpatterson611
    @jaylenpatterson611 2 года назад +2

    Hi, Great video and very informative! I'm having an issue when we run docker-compose up --build though. It loads the nginx page instead of my react app and I cant figure out why not?

    • @codeching
      @codeching  2 года назад

      The development one or prod? In prod we have 2 nginx config, one for routing and one for HTTP server, check both. Also check the Dockerfile of the client, does it build the React succesfully? But I guess it's something about nginx configurations.

  • @ugurgunes95
    @ugurgunes95 Год назад

    Thanks for the video, I've learnt a lot. I hava a problem which is cors policy. When I tried to register from my front end I see The same origin policy error all the time. I've tried so many configuraitons but still the same. Any suggestion?
    Have a nica day!

  • @user-nu4so7zg8r
    @user-nu4so7zg8r Год назад +1

    great tutorial, one thing i didn't understand was the point of the rewrite

    • @codeching
      @codeching  Год назад +1

      Thanks, it's just a rewrite. So when we map the whole application to /api then it could be required if in your application you have route only e.g for '/cars'. When we call /api/cars, then it will call /cars on your application.

  • @admondtamang4119
    @admondtamang4119 2 года назад +1

    Great content. can we also use pm2 with nginx or nginx will be enough for load balancing?

    • @codeching
      @codeching  2 года назад

      You can use anything that you want :)) But I think nginx could be enough. We are using it in real envs. Of course when we moved to Kubernetes environment, there is an Ingress loadbalancer there above it.

  • @tudor14
    @tudor14 Год назад +2

    Great tutorial so far. I have one question - why do we need the client/nginx/default.conf for production? Can we not just do this: COPY --from=development /usr/client/build /usr/share/nginx/html.

    • @codeching
      @codeching  Год назад +1

      Thanks. It could work if you just overwrite the index.html there (and copy all the files) and you're ok with the basic nginx configuration. We're creating a new configuration here where you could set many things. I haven't tried just to overwrite the html but it could work however I think it's a better solution if you create an own nginx config too where you can set up things e.g. port in my case. Usually in normal prod we're using port 80 but here I set 3000 inside nginx config just for demo purpose.

    • @tudor14
      @tudor14 Год назад

      @@codeching Thanks for that. That does make sense. And I've finished the other video with K8s (which was fantastic by the way) and I have another question: Lets say we only want to expose the client route to /, and not expose the server under /api like we do in the ingress-controller. How would we achieve this?

  • @ganapathisubramanyamjayam
    @ganapathisubramanyamjayam 3 года назад +3

    Saved me

  • @dinamohsen9768
    @dinamohsen9768 2 года назад +1

    what if we we use webpack as http server for react?

    • @codeching
      @codeching  2 года назад

      The stack of the applications doesn't matter from the Docker aspect.

  • @hemanthshankar4520
    @hemanthshankar4520 3 года назад +1

    is there any way to achieve this without using docker-compose

    • @codeching
      @codeching  2 года назад +1

      Yes, there are many ways, but this is the good in docker compose, you can run everything together and it has numerous advantage.

  • @lovers_valley
    @lovers_valley Год назад +1

    so efficient coding

  • @aruezechukwuebuka7868
    @aruezechukwuebuka7868 Год назад

    I tried this but whenever I run "npm start" for the client it compiles successfully but nothing shows on localhost:3000, please any idea what could be wrong?

    • @codeching
      @codeching  Год назад

      It could be lot of things. E.g. wrong port mapping, wrong front-end (not running), wrong port for your front-end application, wrong nginx config etc. I can't help you in this in detail sry.

    • @ajaygangarde
      @ajaygangarde 4 месяца назад

      can access front end:- localhost:3050/

  • @mohamedyoussef8835
    @mohamedyoussef8835 Год назад

    Awesome video +++++++++++ 🙂

  • @Lindaine
    @Lindaine 3 года назад +1

    Why don't we setup nginx for the api as well?

    • @codeching
      @codeching  3 года назад +1

      At 23:33 we set it up, or what do you mean?

    • @codeching
      @codeching  3 года назад +1

      If you are talking about the production stack, there in case of client we do that because we would like to serve a static html and we are using nginx as a HTTP server in that case. For node it doesn't required, because we are using node server.
      But in the global Nginx config we put our node application behind /api route.

    • @Lindaine
      @Lindaine 3 года назад

      @@codeching I see, thanks!

    • @Lindaine
      @Lindaine 2 года назад

      @@codeching How about sockjs-node in nginx? I don't understand why it is there

    • @codeching
      @codeching  2 года назад

      @@Lindaine It's used to make the web sockets connection be able to connect to dev server., This is the devserver proxy path if you would like to use it. The webpack sends the update messages through a socket to hot reload.

  • @cetinca
    @cetinca 6 месяцев назад

    On the playlist the order of the video 7 and video 8 could be changed. It will make more sense if Kubernetes is after docerizing the app.

    • @codeching
      @codeching  6 месяцев назад

      I tried to edit it but it's hard because I have multiple videos about these topics :) The order is not so important because the videos are mostly random and not all are built in top of the previous one. But I tried to order it a little bit now. Thank you for your response!

    • @cetinca
      @cetinca 6 месяцев назад +1

      @@codeching thank you.

  • @onewizzard
    @onewizzard 5 месяцев назад

    hmm...maybe you can change the speed on the RUclips menu control. if at .50, and still too fast. maybe it's a you issue because I watched this 2.00 and this video was fine.

    • @codeching
      @codeching  5 месяцев назад

      Hi, there is no speed problem here.

  • @luisjavier5224
    @luisjavier5224 2 года назад +2

    Oh man. you go too fast it's difficult to follow you

    • @codeching
      @codeching  2 года назад +2

      Thank you for watching! :) it's a video, maybe you can pause it any time.

    • @stockholmsyndromeself-trea7517
      @stockholmsyndromeself-trea7517 2 года назад

      @@codeching And I paused many times indeed. It's very informative I did learn a lot.

    • @onewizzard
      @onewizzard 5 месяцев назад

      hmm...maybe you can change the speed on the RUclips menu control. if at .50, and still too fast. maybe it's a you issue because I watched this 2.00 and this video was fine.

  • @nithinkamineni9392
    @nithinkamineni9392 Год назад

    in Nginx file you mentioned
    "proxy_pass client"
    "proxy_pass api;"
    but where are you actually mentioning the urls or ports like this?
    eg:
    server:
    container_name: nanomedicine_server
    restart: unless-stopped
    image: nanomedicine-server-image:1.0.0
    build:
    context: nanomedicine-backend
    target: production
    dockerfile: Dockerfile
    ports: #outside:inside(container)
    - 8080:8080
    networks:
    - shared-network
    depends_on:
    - postgres