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

source nvm.sh in dockerfile onbuild not work #3493

Open
rickywu opened this issue Dec 12, 2024 · 12 comments
Open

source nvm.sh in dockerfile onbuild not work #3493

rickywu opened this issue Dec 12, 2024 · 12 comments

Comments

@rickywu
Copy link

rickywu commented Dec 12, 2024

My situation is:

1 base:builder docker image

ENV NVM_DIR=/opt/nvm

nvm_install.sh

ONBUILD source $NVM_DIR/nvm.sh

another dockerfile to build front-end app:

FROM base:builder as builder

RUN nvm use xxx

nvm command not found error.

I tried ONBUILD bash -c "source $NVM_DIR/nvm.sh" got the same problem, I just want to create one base builder image, user can ignore setup nvm and use node directly.

@ljharb
Copy link
Member

ljharb commented Dec 12, 2024

nvm.sh has to be sourced in every RUN command, i believe.

nvm already provides a dockerfile on dockerhub; is there a reason you cant use that?

@rickywu
Copy link
Author

rickywu commented Dec 13, 2024

Yes, I use in this way. But want to optimize, is possible?

@ljharb
Copy link
Member

ljharb commented Dec 13, 2024

I'm not sure what you'd need to optimize, but the way to have a user not need to know nvm exists is just setting the default alias.

@rickywu
Copy link
Author

rickywu commented Dec 13, 2024

I mean user can skip source nvm.sh and use default node directly in docker image build

@ljharb
Copy link
Member

ljharb commented Dec 13, 2024

That's not something you can really do in a practical sense. You could, I suppose, hardcode the PATH - but why wouldn't you just want the user to have nvm available?

@rickywu
Copy link
Author

rickywu commented Dec 13, 2024

set path seems not a good practice, because other env config also need to be set, such as node_modules dir

I provide base builder image for users with multi node version option, but most of them use npm directly in dockerfile, I have to notify them add source nvm.sh in one RUN command, lot of communication work.

I need nvm set a default version and can be used directly, when need change version then source nvm.sh is acceptable.

@ljharb
Copy link
Member

ljharb commented Dec 13, 2024

I'm not sure if this is possible, although I suspect nvm's own dockerfile allows this. cc @PeterDaveHello for the docker question

@PeterDaveHello
Copy link
Collaborator

What's the scenario for this request? Does the user need to switch between different node.js versions in a Docker image?

@rickywu
Copy link
Author

rickywu commented Dec 16, 2024

Yes, some user need 16, someone need 18, I just want provide only one base image

@PeterDaveHello
Copy link
Collaborator

Maybe using ENTRYPOINT or login shell with bashrc will help?

@rickywu
Copy link
Author

rickywu commented Dec 18, 2024

I tried ENTRYPOINT, but source only effect in new forked shell, so not work

@PeterDaveHello
Copy link
Collaborator

So, what's your ENTRYPOINT command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants