skip to Main Content

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.]

4

Answers


  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.

    Login or Signup to reply.
  2. 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 😉

    Login or Signup to reply.
  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search