DEV Community

Discussion on: Dockerize your React app

Collapse
 
claysam75 profile image
claysam75

After you have updated the Dockerfile for production, you have another two stages - one which actually builds the react app, and the last stage which grabs those built static files from the build step and serves them via NGINX.

Firstly, is the lower case 'as' in the nginx build step a typo or does that do something different to 'AS'.

Secondly, in the docker-compose.prod.yml file, you set the build target as 'production' - ie the last nginx stage in the docker file. How can that run successfully if the build stage it relies on has not been run yet? Is that build stage called when the nginx stage runs?

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Hey, nice catch! yes it's a typo and should be 'AS', in dockerfile lowercase syntax also works exactly the same but it's not prefered..i'll update it to upper case..thank you

For the second question, docker automatically understands that "builder" is used inside the prod stage so it runs the builder first..so the seq of events are like this:

  1. looks in at the target, creates a dependency graph (what requires what)
  2. identifies that prod is relied on builder
  3. runs the builder first
  4. continues with the prod