npm / npm/cli

[BUG]node:16-alpine3.16 and npm -v and other npm options return no output when using image in kubernetes

Open
#5,428 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

Hello,

With docker image creation, I updated to use FROM node:16-alpine3.16 for the image and used that image with kubernetes, but now for some reason npm -v does not return information.

Any command options I try does nothing. It pauses for a few seconds like it is thinking and then drops down to the command prompt with no output. I can even put in fake options and it does the same thing.

It worked fine with our previous use of node:14:alpine.

Note: that /usr/src/app becomes readonly once the container is made and used in kubernetes.

Using the image outside of kubernetes still works fine. Is npm trying to write now to /usr/src/app? How do I address this? In that, if I make do a docker build and then try and connect to the container to get to a comand prompt, I can npm -v fine. It is when I use this image in kubernetes that I have the bad behavior.

Finding who can help with this is kind of unclear. I am not sure if maybe something is going on with the read-only filesystem once in kubernetes. Have you seen this issue and do you have a suggestion on what might be going on and how to fix? Is there a way to have some debugging when I run the npm command so that I can see what it is doing while it pauses before dropping down to the command prompt?

Sincerely,

David

Expected Behavior

I expect to see npm -v return a version

Steps To Reproduce

create a standard dockerfile that uses:

FROM node:16-alpine3.16
You can do the typical WORKDIR /usr/src/app and copy your package* and code into it
I created a user with the same uid/gid I set as runasuser (1001)/runasgroup (3000) in my kubernetes deployment yaml
have CMD "./loop.sh" so it just loops and does hello world message during this troubleshooting. It is actually supposed to launch a web page with:

EXPOSE 3000

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

I use kubectl exec -it /bin/sh to get on the pod and run npm -v.

Environment

npm config is not returning anything as it is now. No options sent to npm work.

npm is supposed to be 8.15.0
It is using alpine 3.16 (tried 3.15 too)

Note: node -v does return a version just fine.  It is whatever version is in the alpine build.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report names no repository files or tests. Reproduce with the supplied Dockerfile, node:16-alpine3.16, a read-only /usr/src/app, and kubectl exec, then compare node:14-alpine and an outside-Kubernetes container while checking npm configuration and output. Done means npm -v and other npm options return their expected output in the Kubernetes pod.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript, kubernetes, nodejs
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.