Node and Yarn
Add Node or Yarn to a container
See Node install instructions.
Use Node image
Use the node image from Docker hub.
This includes Yarn already.
DockerfileFROM node:12
Latest Node from APT
Use the ubuntu image from Docker hub.
APT already supports Node, but you’ll only get a stable version which will behind the latest versions. See the next section to get a newer version of Node.
DockerfileFROM ubuntu RUN apt update RUN apt install -q -y nodejs RUN npm install -g yarn
Node from Deb source
Similar to above, but instead of getting the Node version supported by APT (e.g. 10 or 12), you get a target version that you specify (like 14 or 16).
On the curl line, use setup_14.x or setup_16.x for example (using a literal letter x).
Based on Installation instructions in the Node docs, which covers Ubuntu and Debian. The docs don’t say that you need to run update after adding the souce.
DockerfileFROM ubuntu RUN apt update RUN apt install -q -y curl RUN curl -sL "https://deb.nodesource.com/setup_14.x" | bash - RUN apt update RUN apt -q -y install nodejs RUN npm install -g yarn
Yarn from APT
Set up a plain image then add Yarn to it using apt.
DockerfileFROM ubuntu ENV DEBIAN_FRONTEND=noninteractive RUN apt update RUN apt install -q -y \ apt-utils \ curl \ gnupg RUN apt remove cmdtest && apt remove yarn RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list RUN apt install -q -y yarn
Notes:
DEBIAN_FRONTENDis set to avoid the flow to set region for tzdata.- It found I got errors consistently on
apt updateso switched toapt-get update. - Adding
apt-utilsis not neeeded, but prevents error when usingdebconf. - There is already an
aptpackaged calledyarnwhich is unrelated to JavaScript, so be sure to remove it. - Install
gnupgforapt-keyto work on thecurlline.