1

The official docker image for node is: https://hub.docker.com/_/node. This comes with yarn pre-installed at v1.x. I want to upgrade yarn to v2. However, I can't tell how yarn was installed on this image. It's presumably not via npm because if I do npm list, yarn does not show up in the list. I don't know of another way to install yarn. I thought maybe it was via the package manager for linuxkit, which I believe is the distribution used by the node docker image. However I looked at the package-manager for linuxkit – as I understand it they just use git clone and there are a list of packages available in /pkg in the github repository. However, yarn isn't one of those.

Some steps towards an answer, maybe:

  1. How is the installed version of yarn on node:latest docker image installed? [Maybe that will inform me as to how I can upgrade it]
  2. How can I upgrade yarn on a LinuxKit docker image?
  3. How can I see the Dockerfile for the base image? [I.e. node:latest – is there a Dockerfile for that which tells us how the image was generated? If so that might tell me how yarn was installed.]
geoidesic
  • 4,649
  • 3
  • 39
  • 59
  • 2
    All of the `Dockerfile`s are in https://github.com/nodejs/docker-node, did you look there how Yarn is added? – jonrsharpe Jul 26 '22 at 15:12
  • 1
    Looks like the Yarn version is defined by the `YARN_VERSION` var. – Dave Newton Jul 26 '22 at 15:12
  • @jonrsharpe It's added via `apk` in those Dockerfiles but `apk` yields `command not found` if I `exec` the container. – geoidesic Jul 26 '22 at 15:13
  • 1
    Is it? E.g. https://github.com/nodejs/docker-node/blob/cde9414cb2db0be1a911e9070c6c117de7be705a/18/buster/Dockerfile#L50-L68 doesn't use `apk`. – jonrsharpe Jul 26 '22 at 15:14
  • Not sure. I found this, which suggests it's installed via tarball: https://github.com/nodejs/docker-node/issues/351 – geoidesic Jul 26 '22 at 15:30

4 Answers4

3

The Best Practices Guide recommends for (simple) local installs

FROM node:6

ENV YARN_VERSION 1.16.0

RUN yarn policies set-version $YARN_VERSION

in your Dockerfile. This guide is worth to be read anyway ;-)

JeffRSon
  • 10,404
  • 4
  • 26
  • 51
3

If you can do something on runtime,
simply use below command to install the Yarn version you want:

yarn set version stable

On 2022-11-23, stable will install Yarn 3.3.0.

Franck
  • 560
  • 7
  • 20
1

According to Dockerfile it is installed via tarbar in both in alpine and debian versions:

  && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
  && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
  && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
  && mkdir -p /opt \
  && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
  && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
  && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
  && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \

You can use the similar commands to download and use ln to create symlink for your version like above.

Qasim Sarfraz
  • 5,822
  • 2
  • 20
  • 26
0
  1. according to the Dockerfile, you can change the ENV YARN_VERSION to a special version.

refs

https://github.com/nodejs/docker-node/blob/main/18/alpine3.16/Dockerfile#L77

https://github.com/nodejs/docker-node#image-variants

https://github.com/nodejs/docker-node/blob/main/versions.json

enter image description here

xgqfrms
  • 10,077
  • 1
  • 69
  • 68
  • Sorry but maybe you misunderstood the question? This isn't the answer. I'm not asking for the version, I'm asking for the installation method. – geoidesic Jul 26 '22 at 15:28
  • 2
    `yarn install` _doesn't_ install the latest version of Yarn. It installs the relevant dependencies _using_ whichever Yarn version is installed. And according to _what_ Dockerfile - what are you quoting? This seems to be some other Dockerfile _using_ a Node image, not the base image (which is `node:12-alpine`, defined by e.g. https://github.com/nodejs/docker-node/blob/47eda0d3d0d3e5c339a4d0a99a1c3882f697234c/12/alpine3.15/Dockerfile). – jonrsharpe Jul 26 '22 at 15:59