Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
mrdeshapiro opened this issue Aug 26, 2022 · 4 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@mrdeshapiro
Copy link

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.
@mrdeshapiro mrdeshapiro added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Aug 26, 2022
@mrdeshapiro
Copy link
Author

I got pod up again and ran node -v:

node -v
v16.17.0

@carrodher
Copy link

carrodher commented Sep 1, 2022

I was able to reproduce the same issue when moving from node 14.20.0 to 16.17.0. It seems there are two aspects to reproduce the issue:

  • Use a recent NodeJS version, i.e 16.17.0
  • and use a non-privileged user (see below description)

Using a privileged (root) user ✅

Creating a Dockerfile with the USER directive set to root

USER root

so the container is built and executed with that root user everything works as expected:

root@fb304889a320:/# npm --version
8.15.0

root@fb304889a320:/# npm --help
npm <command>

Usage:

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term>
npm help npm       more involved overview

All commands:

    access, adduser, audit, bin, bugs, cache, ci, completion,
    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
    edit, exec, explain, explore, find-dupes, fund, get, help,
    hook, init, install, install-ci-test, install-test, link,
    ll, login, logout, ls, org, outdated, owner, pack, ping,
    pkg, prefix, profile, prune, publish, rebuild, repo,
    restart, root, run-script, search, set, set-script,
    shrinkwrap, star, stars, start, stop, team, test, token,
    uninstall, unpublish, unstar, update, version, view, whoami

Specify configs in the ini-formatted file:
    /.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

[email protected] /opt/bitnami/node/lib/node_modules/npm

root@fb304889a320:/#

Please note the root@... prompt which indicates the container is being executed with the root user. For the above tests, everything is working fine and both commands (npm --version and npm --help) return the expected output.

Using a non-privileged (1001) user 🔴

Creating a Dockerfile (the same as above) but with the USER directive set to 1001

USER 1001

so the container is built and executed with that 1001 user the npm binary is not working as expected:

I have no name!@9341b6941d34:/$ npm --version

I have no name!@9341b6941d34:/$ npm --help

I have no name!@9341b6941d34:/$ echo $?
243
I have no name!@9341b6941d34:/$ 

Please note the I have no name!@... prompt which indicates the container is being executed as a non-privileged/undefined user. For the above tests, now both commands (npm --version and npm --help) return an empty answer, the exit code 243 in both cases.


Doing the same exercise (root and non-root user) but using node 14.20.0 (and others) everything works as expected

@carrodher
Copy link

There were similar issues in the past related to other tools, see nodejs/node-gyp#2333 (comment)

@mrdeshapiro
Copy link
Author

mrdeshapiro commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

2 participants