'npm start runs my updated code, but docker runs with a outdated code
Yeah it's confuse a lot, when i start my application with npm start like normally do, it starts fine and i can see my chances and updates but when i create a docker-compose file and a dockerfile and runs into a docker container, it runs a very outdated version of my code.
I tried everything to fix this issue, i can't understand where does docker gets this outdated code that doesn't even exist in my machine or in the project. i cleaned cache also, i removed all images / containers but still the same thing
the question is, where docker finds this code and why does it finds and why does docker run this code that doesn't even exist in my local machine or my code? why can't he run my code like npm start do?
i can't find the issue with it
Here the docker file and docker compose file for a simple local run
FROM node:12.18.4 as build
WORKDIR /app
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN npm ci
RUN npm i react-toastify
COPY . /app
RUN rm .env
COPY .env.production .env
RUN npm run build
# production environment
FROM nginx:1.17.9-alpine
COPY --from=build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
COPY nginx/decode.crt /etc/nginx/decode.crt
COPY nginx/decodewp.key /etc/nginx/decodewp.key
EXPOSE 80
EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]
--------------------------------------------------
version: "3.6"
services:
decode.up4biz.frontend:
build:
context: .
dockerfile: Dockerfile
ports:
- "4000:80"
- "4001:443"
restart: always
stdin_open: true
volumes:
- './:/app'
- '/app/node_modules'
environment:
- CHOKIDAR_USEPOLLING=true
Solution 1:[1]
Finally i found something, there was a issues into my docker file, i've created each file for each different environments and changed the nginx configuration. I thought it was just a build issues but it wasn't, it was just the nginx with docker not talking with each other well Here's my dockerfile
FROM nginx:stable-alpine
ARG ENV
COPY . /app
WORKDIR /app
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN apk --no-cache add npm
RUN npm install --package-lock
RUN npm i react-toastify
COPY .env.development .env
RUN npm run build-development
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx-development.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
And here my nginx configuration that fixed the issue:
location / {
root /app/build;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
what fixed the problem was this line here
root /app/build;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mahmoudafer |
