title: Dockerizing react for production not working
body: <p>I have created a <code>Dockerfile</code> and <code>Docker-compose.yml</code> for containerzing my <code>create-react-app</code> to production. My problem of understanding is how should I create the production build if the scripts that are needed to run the command are <code>dev-dependencies</code>?
  Also I can`t find anything on <a href="https://create-react-app.dev/docs/deployment" rel="nofollow noreferrer">deployment docs</a>.</p>
  <pre><code> &gt; [builder 7/7] RUN yarn build:
  #13 0.507 yarn run v1.22.19
  #13 0.556 $ react-scripts build
  #13 0.579 /bin/sh: react-scripts: not found
  #13 0.590 error Command failed with exit code 127.
  #13 0.590 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  ------
  executor failed running [/bin/sh -c yarn build]: exit code: 127
  ERROR: Service 'app' failed to build : Build failed
  `docker-compose` process finished with exit code 1
  </code></pre>
  <p><strong>package.json</strong></p>
  <pre><code>{
    &quot;version&quot;: &quot;0.1.0&quot;,
    &quot;private&quot;: true,
    &quot;dependencies&quot;: {
      &quot;react&quot;: &quot;^18.1.0&quot;,
      &quot;react-dom&quot;: &quot;^18.1.0&quot;,
      &quot;react-i18next&quot;: &quot;^11.17.2&quot;,
      &quot;react-router-dom&quot;: &quot;^6.3.0&quot;,
    },
    &quot;scripts&quot;: {
      &quot;start&quot;: &quot;react-scripts start&quot;,
      &quot;build&quot;: &quot;react-scripts build&quot;,   &lt;--- THIS WILL BE USED FOR PRODUCTION
      &quot;test&quot;: &quot;react-scripts test&quot;,
      &quot;eject&quot;: &quot;react-scripts eject&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;react-scripts&quot;: &quot;5.0.1&quot;,   &lt;--- THIS WILL NOT BE INSTALLED WITH --production FLAG
      &quot;tailwindcss&quot;: &quot;^3.0.24&quot;,
      &quot;typescript&quot;: &quot;^4.6.3&quot;
    }
  }
  </code></pre>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM node:18-alpine AS builder
  ENV NODE_ENV production
  
  # Add a work directory
  WORKDIR /app
  
  # Cache and Install dependencies
  COPY package.json .
  COPY yarn.lock .
  RUN yarn install --production   &lt;---- THIS DOES NOT INSTALL DEV DEPENENCIES
  
  # Copy app files
  COPY . .
  
  # Build the app
  RUN yarn build     &lt;---- THIS CAUSES THE CRASHING
  
  # ---------------------------------------------------
  
  # Bundle static assets with nginx
  FROM nginx:1.23.1-alpine AS production
  ENV NODE_ENV production
  
  # Copy built assets from builder
  COPY --from=builder /app/build /usr/share/nginx/html
  
  # Add your nginx.conf
  COPY nginx.conf /etc/nginx/conf.d/default.conf
  
  # Expose port
  EXPOSE 80
  
  # Start nginx
  CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: &quot;3.8&quot;
  
  services:
    app:
      container_name: my_app
      build:
        context: .
        target: production
        dockerfile: Dockerfile
  </code></pre>