<p>I'm setting my react application into docker but when I run the container in the Kubernetes cluster I get the next error:</p>
<pre><code>internal/modules/cjs/loader.js:1032
  throw err;
  ^
Error: Cannot find module '/usr/src/app/API_URL'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
</code></pre>
<p>Here is my docker file for the frontend (building this image is successful):</p>
<pre><code>###########
# BUILDER #
###########

# pull official base image
FROM node:14.4.0-alpine3.10 as builder

# set work directory
#WORKDIR /usr/src/app

# install dependencies and avoid `node-gyp rebuild` errors
ADD package*.json ./usr/src/app/
WORKDIR /usr/src/app
RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    &amp;&amp; npm install \
    &amp;&amp; apk del .gyp

# copy our react project
COPY . /usr/src/app

# perform npm build
ARG API_URL
ENV REACT_APP_HOST_IP_ADDRESS=${API_URL}
RUN REACT_APP_HOST_IP_ADDRESS=${API_URL} \ 
  npm run build

#########
# FINAL #
#########

# pull official base image
FROM node:14.4.0-alpine3.10

# set work directory
WORKDIR /usr/src/app

# install serve - deployment static server suggested by official create-react-app
RUN npm install -g serve

# copy our build files from our builder stage
COPY --from=builder /usr/src/app/build ./build
</code></pre>
<p>and my manifest.yaml for the frontend (execute this part has no problem):</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
    name: frontend-deployment
    labels:
        app: frontend
spec:
    replicas: 1
    selector:
        matchLabels:
            app: frontend
    template:
        metadata:
            labels:
                app: frontend
        spec:
            containers:
            - name: frontend
              image: frontend-image
              ports:
              - containerPort: 3000              
              args:                
                - API_URL
                - 175.1.25.25:8000
            imagePullSecrets:
            - name: registry-front
</code></pre>
<p>Any help with this? thanks in advance</p>

Jefferson
<p>Kubernetes <code>args:</code> overrides the Dockerfile <code>CMD</code>.  So in this setup you're telling the container to run <code>API_URL 175.1.25.25:8000</code> instead of the normal image <code>CMD</code>; that's not what you expect.</p>
<p>In a Docker Compose setup you can tell Compose to <code>build:</code> an image, and within that, pass <code>args:</code>.  Kubernetes never builds its own images, though; it only runs images that have already been built and pushed to some registry.  You can't change compile-time settings that get passed in Dockerfile <code>ARG</code> at deployment time.</p>
<p>In your CI system, when you build the image, you need to pass the argument there; the CI system would need to run something like</p>
<pre class="lang-sh prettyprint-override"><code>docker build --build-arg API_URL=175.1.25.25:8000 -t frontend-image .
docker push frontend-image
</code></pre>
<p>to produce an image with that <code>API_URL</code> value baked in; and then when you actually go to run the image, delete the <code>args:</code> from the deployment spec to run the default command for the image.</p>
