I’m constructing a Docker image for a static website, but the process aborts due to a missing ‘.env’ file in caching. Below is my Dockerfile:
FROM node:14
WORKDIR /project
COPY app.json .
RUN npm install -g react-scripts
RUN npm install
COPY buildConfig.js .
COPY env.sample .
EXPOSE 5000
CMD ["react-scripts", "start"]
had sum issues with that! try adding a COPY .env . before npm install so the file gets in the build. sometimes simplest change works due to how docker caches layers. good luck!
hey, i’ve seen similar cache issues, maybe try cp env.sample .env before npm install? not totally sure if that fixes it, but curious, has anyone found a work around that really nailed it?
In my experience, the key to avoiding caching issues in Docker builds is to carefully manage the file copy order. Instead of copying the environment file after the npm install, change the order so that the necessary configuration is in place beforehand. I found that this approach reduces unexpected caching of stale files. It is also preferable to maintain consistency between your sample and active environment files during the build process, ensuring that changes in the configuration trigger appropriate caching behavior throughout each layer.
hey, try building with --no-cache. it flushes old layers and might push the .env in correctly. i had similar probs and this did the trick for me sometimes