goldbergyoni / goldbergyoni/nodebestpractices
Is using cache for npm install in docker safe?
- Dominant language
- Dockerfile
- Stars
- 106k
- Forks
- 10.7k
- PR merge metrics
- No merged PRs in 30d
Description
I was wondering about the point `8.1 Use multi-stage builds for leaner and more secure Docker images` and the example stated there:
```Dockerfile
FROM node:14.4.0 AS build
COPY . .
RUN npm ci && npm run build
FROM node:slim-14.4.0
USER node
EXPOSE 8080
COPY --from=build /home/node/app/dist /home/node/app/package.json /home/node/app/package-lock.json ./
RUN npm ci --production
CMD [ "node", "dist/app.js" ]
```
My idea here for speed up this build by using the cache:
```Dockerfile
FROM node:14.4.0 AS build
COPY . .
RUN npm ci --cache .npm --prefer-offline && npm run build
FROM node:slim-14.4.0
USER node
EXPOSE 8080
COPY --from=build /home/node/app/.npm ./.npm
COPY --from=build /home/node/app/dist /home/node/app/package.json /home/node/app/package-lock.json ./
RUN npm ci --production --cache .npm --prefer-offline
CMD [ "node", "dist/app.js" ]
```
But the only consideration that I have is `Is it safe`?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with section 8.1, “Use multi-stage builds for leaner and more secure Docker images,” and review the proposed Dockerfile alongside the existing example. Determine whether copying the npm cache between stages is safe, including any security or reproducibility concerns. Done means the documentation clearly answers the safety question and records relevant caveats.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, nodejs
- Domain
- devops, security
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100