I would like to install Node.js with yarn.pkg in my Dockerfile.
The Dockerfile is for a Laravel8/PHP8 project.
This is my actual try:
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
RUN apt-get update -y
&& apt-get install -y --no-install-recommends
nodejs
yarn
mysql-client
If I try it this way, I got this output on my shell:
=> CACHED [ 8/20] RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - 0.0s
=> ERROR [ 9/20] RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 0.4s
------
> [ 9/20] RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -:
#12 0.331 Warning: apt-key output should not be parsed (stdout is not a terminal)
#12 0.384 gpg: Segmentation fault
#12 0.384 no valid OpenPGP data found.
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -]: exit code: 2
Is there a way to solve this problem?
If you need more information about it, please let me know.
Regards,
Manny
2
Answers
Top-Master, thank's a lot for your input. It has helped me a lot to find my solution.
Here it is...
I have used the Dockerfile you posted above and made some small changes:
The problem was, the
RUN npm install -g yarn
command run into an error and the build fails. After some googling around I've found this webpage https://docs.npmjs.com/downloading-and-installing-node-js-and-npm.They recommend, that npm should be installed separately because of the directory structure and user rights. They are not the same if you install npm with Node.js together.
So I've done this:
For me (and I hope for many other people too) it works now :)
Thank's again!
Have a nice time!
Hmm…
NPM
(Node package manager) is installed along withNode.js
, andYarn
is just a module that is installed likenpm install -g yarn
Simply edit and use what another post mentions like: