Skip to content

Install Yarn as suggested in official documentation #351

Closed as not planned
Closed as not planned

Description

@AlicanC

I had an image which was built before Yarn was added to this project.

I installed Yarn like this:

FROM node:boron

# Update
RUN apt-get update -y

# Install apt-transport-https for Yarn repository
RUN apt-get install apt-transport-https -y

# Add Yarn repository
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

# Update
RUN apt-get update -y

# Install Yarn
RUN apt-get install yarn -y

It was working perfectly fine until I decided to update my image and use the provided Yarn instead of my own. Now my project's postinstall script is crashing with Error: Cannot find module '/bin/yarn.js'. If I try to install my own Yarn like above, yours just replace mine and it still doesn't work.

Could you just install Yarn as suggested in the official docs?

Activity

  1. chorrell commented on Mar 30, 2017

    @chorrell
    Contributor

    I guess the postinstall script has a hard-coded path to yarn? We install yarn in /usr/local/bin which takes precedence over /bin in the PATH variable which is why your version isn't being called.

    The chosen installation method was because at the time we added yarn (if I remember this right) the debian package wasn't gpg signed. The installation method we chose is based on Docker's recommendation for Official images: https://github.com/docker-library/official-images#security

    Also, and again my memory is a bit fuzzy here, we worked with the some members of the yarn community on this and this installation method was the best option at the time. I think there were some other issues too, like the debian package assumed the node binary was called nodejs and also installed via a debian package.

    The PR that landed yarn and the discussion about install method etc. are here fwiw:

  2. karfau commented on Apr 13, 2017

    @karfau

    As a maybe related side note: the docker files for v6.10 (e.g. alpine ) contain the following line:

    ENV YARN_VERSION 0.21.3
    

    but running docker run --rm node:6.10.2-alpine yarn --version
    results in the output 0.22.0

    This might cause some confusion when people try to find out which version is coming with which docker image.

  3. Starefossen commented on Apr 13, 2017

    @Starefossen
    Member

    Also, the final image size is a concern when installing yarn, this was the most space efficient method.

  4. Daniel15 commented on May 13, 2017

    @Daniel15

    Also, the final image size is a concern when installing yarn, this was the most space efficient method.

    That's right - The main reason Yarn is installed using the standalone .js file is because it used to be much smaller than the other releases of Yarn. However, in Yarn 0.24.x, we updated the Debian package and tarball to just use the bundled .js file rather than packing the individual files, so the sizes are comparable now. I filed #401 for that, before seeing this issue 😛

    the debian package wasn't gpg signed

    Debian package is GPG signed if you install it via the package repository. In general, Debian doesn't really GPG sign individual .deb files, only the metadata files for package repositories are signed. You can use debsigs to sign individual .deb files, but Debian doesn't use it out-of-the-box.

    . I think there were some other issues too, like the debian package assumed the node binary was called nodejs and also installed via a debian package.

    You just need to install it with --no-install-recommends.

  5. Starefossen commented on May 14, 2017

    @Starefossen
    Member

    Thanks for the info @Daniel15! We should revisit whether we should install using the debian repo or continue using the tarball as we do today.

  6. pesho commented on May 14, 2017

    @pesho
    Contributor

    @Starefossen we do not use the tarball today.

  7. nschonni commented on Aug 4, 2018

    @nschonni
    Member

    Was playing with this and it looks like this would be what is required for the minimum

    RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn apt-key add - && \
        echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
        apt-get update && \
        apt-get install --no-install-recommends yarn
    

    You can do the apt-get install --no-install-recommends yarn=$YARN_VERSION but the deb packages have a -1 build part that also needs to be added.
    The apt-transport-https can also be skipped if the deb URL is changed to HTTP

  8. nschonni commented on Aug 4, 2018

    @nschonni
    Member

    Alpine 3.6+ can also do the install now with apk add yarn https://yarnpkg.com/en/docs/install#alpine-stable

  9. geoidesic commented on Jul 26, 2022

    @geoidesic

    The way this has been installed makes it difficult to upgrade yarn

  10. SimenB commented on Jul 27, 2022

    @SimenB
    Member

    Shouldn't be, instructions in https://yarnpkg.com/getting-started/install remain valid afaik

  11. MikeMcC399 commented on Apr 13, 2026

    @MikeMcC399
    Contributor

    I suggest to close this old issue. The Yarn v1 installation script for Docker images based on versions of Node.js <=25 is stable. For upcoming new images based on Node.js >=26, Yarn v1 will no longer be installed (see Yarn v1 Classic bundling).


    The original problem was with node:boron (Node.js 6.x) around 10 years ago, on Debian 9 (stretch).

    With node:6.17.1

    Yarn 1.15.2 is installed to /usr/local/bin/yarn

    The frozen Yarn v1 documentation on https://classic.yarnpkg.com/en/docs/install describes either:

    npm install --global yarn # generically

    or

    apt install yarn # for Ubuntu / Debian (after environment setup)

    or

    apk add yarn # for Alpine

    The Yarn v1 download script embedded in the templates, for example in Dockerfile-debian.template, downloads from https://yarnpkg.com/downloads, using a Yarn tarball on the advice of the Yarn v1 team.

    This method continued to be successful whilst there was an incident yarnpkg/yarn#9216 in Jan 2026, where users who were using the method for Ubuntu/Debian from https://classic.yarnpkg.com/en/docs/install (outside of Node.js Docker images) were suddenly unable to verify the download due to an expired key.

    The script to install Yarn v1 is dynamically removed when the templates are applied for Node.js >=26 and no Yarn is installed.

    The report in #351 (comment) above regarding upgrade difficulties wasn't described in any detail. Yarn v1 is frozen at yarn@1.22.22, released Mar 9, 2024 and this is the version hard-coded into the templates on the assumption that any update would be an unexpected exception.

    Based on the above, there seems to be no reason at this time to make any changes to the Yarn v1 installation script for its remaining lifetime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions