DEV Community

Cover image for Containerize React app with Docker for Production

Containerize React app with Docker for Production

Mubbashir Mustafa on March 25, 2020

Docker - an overview Docker is an open platform for developing, shipping, and running applications. Docker ensures quick delivery of your software ...
Collapse
 
xai1983kbu profile image
xai1983kbu

Hi! Thank you for your article!
Is it possible to containerize NextJs App with Nginx in one container?
I don't understand how to run two processes in one container.
I find this answer stackoverflow.com/a/63038894/9783262 but have no success yet.

Can we containerize only NextJs App (without Nginx) for usage with "Fargate + Application Load Balancer"?

Collapse
 
xai1983kbu profile image
xai1983kbu • Edited

I manage to launch containerize NextJs App without Nginx
Example with Pulumi
github.com/pulumi/examples/issues/...

It's interesting now - Is it the right way (don't use Nginx)?

Collapse
 
mubbashir10 profile image
Mubbashir Mustafa

Umm, I would throw in Nginx there to do the load balancing, caching, compressing, etc. But yeah that's just my opinion :)
If you are generally interested in why we want to use Nginx with node server, this might help: expressjs.com/en/advanced/best-pra...

Thread Thread
 
mubbashir10 profile image
Mubbashir Mustafa

Btw you can add more than one container in ECS. That's how usually the node js apps are deployed (the other being a sidecar container).

Thread Thread
 
xai1983kbu profile image
xai1983kbu

Thank you soo much!

Thread Thread
 
abhipise81 profile image
Abhishek Pise

Can you guide me How to deploy Preact app into ecs?

Thread Thread
 
mubbashir10 profile image
Mubbashir Mustafa
Collapse
 
jhonatangiraldo profile image
Jhonatan Giraldo

Hey, great article. A couple of questions:

  1. Why do we need to add node_modules to the path? ENV PATH /app/node_modules/.bin:$PATH
  2. Why do you copy explicitly the package.json if anyway you will copy everything from the root? COPY ./package.json /app/ # <-- redundant? COPY . /app
  3. What is the advantage of running nginx in the foreground instead of daemon? CMD ["nginx", "-g", "daemon off;"]
Collapse
 
bjkeller profile image
Ben Keller

The answer to 2 is that Docker builds images in layers with rebuilds being triggered for all layers after a change has been detected. Since installing dependencies takes time and happens less frequently than code updates, it is better to isolate that step to avoid having dependencies installed every time you tweak your code.

Collapse
 
jayanath profile image
Jay Amaranayake

Well written series! nicely done!

Collapse
 
mubbashir10 profile image
Mubbashir Mustafa

Thank you!

Collapse
 
jhonatangiraldo profile image
Jhonatan Giraldo

Sorry, I got another question. Why did you use the module index? Trying out by myself nginx uses index.html when accessing the URL without defining that the index is index.html|index.htm

Collapse
 
kvssankar profile image
Kvs Sankar Kumar

y do we need ngnix server, cant use node to serve the static files dire