-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Comments
I got pod up again and ran node -v: node -v |
I was able to reproduce the same issue when moving from node
Using a privileged (
|
There were similar issues in the past related to other tools, see nodejs/node-gyp#2333 (comment) |
Certainly, you should be able to run this as a non-privileged (non-root)
user, right? I hope this issue can get resolved soon.
…On Thu, Sep 1, 2022 at 4:12 AM Carlos Rodríguez Hernández < ***@***.***> wrote:
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:
***@***.***:/# npm --version
8.15.0
***@***.***:/# 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
***@***.*** /opt/bitnami/node/lib/node_modules/npm
***@***.***:/#
Please note the ***@***.*** 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 ***@***.***:/$ npm --version
I have no ***@***.***:/$ npm --help
I have no ***@***.***:/$ echo $?
243
I have no ***@***.***:/$
Please note the I have no ***@***.*** 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
—
Reply to this email directly, view it on GitHub
<#5428 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A2X3SMAZXPYG4NZP4U6EUX3V4BQOFANCNFSM57WWCRBQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Is there an existing issue for this?
This issue exists in the latest npm version
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.
The text was updated successfully, but these errors were encountered: