docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

`yarn` not found in `node:alpine`

Open beldur opened this issue 8 years ago • 71 comments

I'm using the node:alpine image in a gitlab-ci build. Since a few minutes ago I get the following error in gitlab-ci:

$ yarn config set cache-folder .yarn
/bin/sh: eval: line 50: yarn: not found
ERROR: Job failed: exit code 127

My .gitlab-ci.yaml:

build:
  image: node:alpine
  stage: build
  script:
    - yarn config set cache-folder .yarn
    - yarn
    - yarn build

beldur avatar Mar 16 '18 11:03 beldur

I'm happy we were not the only one experiencing this issue 😅 , reverting to a earlier tag was our solution but kudos to the community on this form for providing suggestions.

CalebKing3 avatar Mar 16 '18 17:03 CalebKing3

I'm happy we were not the only one experiencing this issue 😅 , reverting to a earlier tag was our solution but kudos to the community on this form for providing suggestions.

I think the whole world ended up here when they realized their builds were not passing lol!

cecton avatar Mar 16 '18 18:03 cecton

The fix seems to have made its way through the system. I've just had a GitLab CI build pass using the node:alpine image.

djbingham avatar Mar 16 '18 18:03 djbingham

@SimenB @LaurentGoderre - PR with changes to prevent this sort of thing happening again - https://github.com/nodejs/docker-node/pull/658

danielwhatmuff avatar Mar 19 '18 11:03 danielwhatmuff

I wrote up a blog post to explain how/why this happened, why it's not completely unexpected and can happen again, and what you can do to protect against it in future: https://renovateapp.com/blog/docker-mutable-tags

In summary:

  1. Docker tags can change at any time. They are mutable and that is by design, not fault
  2. Even a Docker tag that looks like semver (e.g. node:8.10.0) still has the properties of a tag and can be changed/updated at any time, like happened here
  3. There are valid reasons for the image a tag points to to be changed (such as refactoring the Dockerfile or a security patch to the base), so it's not a good idea to insist that a tag that looks like a semver should never be changed
  4. The only way to ensure your build is reproducible/consistent is to use Docker digests as the identifier instead of the tag
  5. You can conveniently still include a Docker tag in the digest for human readability, e.g. node:8.10.0-alpine@sha256:a55d3e87802b2a8464b3bfc1f8c3c409f89e9b70a31f1dccce70bd146501f1a0
  6. If you were using digests for your node base images instead of tags, you not only wouldn't have "accidentally" upgraded to the new broken image in the first place, and even if you had updated on purpose then you could have immediately rolled back the digest in your Dockerfile once you discovered the break, instead of waiting hours
  7. Beyond that, these digests are a little "developer-unfriendly" to update by hand, but open source tools to automate it exist

rarkins avatar Mar 19 '18 11:03 rarkins

I believe there is a much simpler solution: if you use Docker for your work, host your own registry and update the images when you need to.

cecton avatar Mar 20 '18 16:03 cecton

@cecton no build time Internet is good for private projects, but not open source development. Also, it does not solve the problems with not having a repeatable build when debugging.

oyvindwe avatar Mar 20 '18 16:03 oyvindwe

That should read: “no build time Internet dependencies”

oyvindwe avatar Mar 20 '18 16:03 oyvindwe

Yes actually, you made a good point... I was more thinking about professional projects.

cecton avatar Mar 20 '18 17:03 cecton

Fixed by adding

RUN apk add --no-cache --virtual .build-deps \
    ca-certificates \
    wget \
    tar && \
    cd /usr/local/bin && \
    wget https://yarnpkg.com/latest.tar.gz && \
    tar zvxf latest.tar.gz && \
    ln -s /usr/local/bin/dist/bin/yarn.js /usr/local/bin/yarn.js && \
    apk del .build-deps

from https://hub.docker.com/r/jfyne/node-alpine-yarn/dockerfile to my Dockerfile.

jwineman avatar Jul 24 '19 18:07 jwineman

For me the issue was in using singlequotes in Dockerfile CMD command

CMD ['yarn', 'start'] // Wrong
CMD ["yarn", "start"] // Correct

jstorm31 avatar Apr 13 '21 10:04 jstorm31