4

I tried many ways to solve this problem, but it's not working. I have an angular app, I created a Dockerfile with the code below:

FROM node:latest AS ng-builder
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
RUN $(npm bin)/ng build --prod


FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=ng-builder /app/dist/sca-front /usr/share/nginx/html

EXPOSE 80

My application works well when running "ng s". But when I create an image on Docker, it doesn't work. I have no proxy, no vpn, a good internet connection...

These errors/warnings are shown:

npm notice 
npm notice New patch version of npm available! 7.0.3 -> 7.0.7
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.7>
npm notice Run `npm install -g [email protected]` to update!
npm notice
npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! request to https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz failed, reason: Socket timeout

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-11-01T01_24_40_819Z-debug.log

I tried call "RUN npm RUN npm install -g [email protected]" because of version of angular...but it looks like an timeout. I tried change the npm version on docker...but it doesn't work.

I tried the dockerfile in a new/small project, it's working. But in a bigger project...

6
  • why dont you run ng build outside of the container in a shell script and then in your docker file just have FROM nginx onwards and copy the angular build directory to nginx html. This way you dont need to have a node build done in docker at all. Commented Nov 1, 2020 at 1:34
  • I would search for things like stackoverflow.com/questions/20430371/… Commented Nov 1, 2020 at 1:43
  • @Abe I could do this, but in many languages and technologies, the good way is to build the application due to CI/CD. Anyway, thanks Commented Nov 1, 2020 at 1:54
  • @Ben W, actually, the internet works, but maybe there is a timeout Commented Nov 1, 2020 at 1:55
  • @Dockerizandu good approach for the CI/CD, nevertheless you want repeatable builds. Copy both the package.json and the package-lock.json in the image and try using npm ci instead of npm install. Commented Nov 1, 2020 at 10:42

1 Answer 1

2

I experienced an error similar to this while trying to create a container on Docker for my react app. I solved it using the node:14-apline for the base image and installed npm@latest just before installing packages.

Note: You can decide to install npm@7 instead.

FROM node:14-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install npm@latest

RUN npm install

COPY . ./

CMD ["npm","run","start"]

https://github.com/npm/cli/issues/2031#issuecomment-715935308

Sign up to request clarification or add additional context in comments.

2 Comments

I will test soon and I will give you a feedback! Thanks
Great! I'll be looking to forward to knowing how if it works out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.