docker-node: yarn not executable

using :9 image.

recent changes made yarn not executable.

/usr/local/bin/yarn: Permission denied

chmod a+rwx  /usr/local/lib/node_modules/yarn/bin/yarn*
chmod a+rwx  /usr/local/bin/yarn*

as a workaround fixes it

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 30 (7 by maintainers)

Commits related to this issue

Most upvoted comments

For now, a simple workaround is to make sure yarn.js is executable after the install:

npm i -g yarn && chmod +x /usr/local/lib/node_modules/yarn/bin/yarn.js

I was hitting this when using node:8.11-alpine and installing yarn with NPM.

I didn’t realise yarn was included with the base image, so I removed npm install -g yarn and it solved the issue.

Installing yarn via npm is not recommended because they think it’s not secure enough, not because it shouldn’t work.

Installation of Yarn via npm is generally not recommended. When installing Yarn with Node-based package managers, the package is not signed, and the only integrity check performed is a basic SHA1 hash, which is a security risk when installing system-wide apps.

Also, installing it via npm makes sure we always get the latest version of yarn, instead of depending on the image’s version or the distro’s repo.

Anyway, what we have so far:

  • node:9.7: works
  • node:9.8: unstable
  • node:9.9.0: unstable
  • node:6: works
  • node:8: unstable

I understand this is no simple bug and there are simple workarounds available already, so I guess we might have to be happy with those even though yarn is getting more and more popular.

This is working for me as a work around using Docker and node:8 image:

FROM node:8

# Remove the version of yarn that is coming with node:8 & Install latest yarn
RUN rm -f /usr/local/bin/yarn && \
  curl -o- -L https://yarnpkg.com/install.sh | bash && \
  chmod +x ~/.yarn/bin/yarn && \
  ln -s ~/.yarn/bin/yarn /usr/local/bin/yarn

@hjanuschka @SimenB Hey, I just ran into this problem too and I found out why. On the previous node images, the pre-installed yarn was so old (version 0.x) we had to do a npm i -g yarn to get the latest version.

Now we already get the latest version of yarn pre-installed, so there’s no need for it anymore.

However, if we still do npm i -g yarn, we get the permission denied error. So, I guess this is still an issue, even though it’s a minor one.

I can reproduce this, but not with --no-bin-links. Reading the bin links code it seems not ready for two links pointing to the same place (as the yarn package does): e.g. its dos2Unix function will be run two async, each stat()ing the file, then rewriting it, then rechmoding it. The “right” interleave (stat1, rewrite1, stat2 (gets bad perms), chmod1, rewrite2, rechmod2) will result in lost permissions.

I’m hitting this too across projects running in CircleCI, with tags circleci/ruby:2.5.1-node-browsers and circleci/node:8.11.1. It’s intermittent. Will try the above fix for now. I’m not sure if both of these are based off the official docker-node images?

@chorrell you’re right! I couldn’t always reproduce it here either.

But, if you try it on node:9.7, you can see it always works: docker run --rm node:9.7 sh -c 'npm i -g yarn && yarn -v'

I’ve checked the npm version on both images and they’re the same (5.6.0), so that’s not it. There’s something funky on the node:9.8 image.

@hjanuschka try removing your local image to make sure you get the latest one: docker rmi node:latest

Then run docker run --rm node:latest sh -c 'npm i -g yarn && node -v && yarn -v'

Edit: this is what I get:

~ docker run --rm node:latest sh -c 'npm i -g yarn && node -v && yarn -v'
Unable to find image 'node:latest' locally
latest: Pulling from library/node
f2b6b4884fc8: Pull complete
4fb899b4df21: Pull complete
74eaa8be7221: Pull complete
2d6e98fe4040: Pull complete
452c06dec5fa: Pull complete
7b3c215894de: Pull complete
c2139be2d901: Pull complete
7c9b0e13f02b: Pull complete
Digest: sha256:59aff2d9898e2b3d35d7656bf57bf61c2dcaedac58b8c3934b8963904d27c437
Status: Downloaded newer image for node:latest
/usr/local/bin/yarnpkg -> /usr/local/lib/node_modules/yarn/bin/yarn.js
/usr/local/bin/yarn -> /usr/local/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.5.1
added 1 package in 0.579s
v9.8.0
sh: 1: yarn: Permission denied

@hjanuschka yep, just reproduced it with node:latest. On node:9.7 I don’t get the error.

Alternatively, removing npm i -g yarn fixes it for node:latest.

Edit: btw, just tested the chmod +x /usr/local/bin/yarn and that works too for node:latest, thanks for that 😃

very strange, i could have sworn that i reproduced it on ci.

docker run --rm node:9 sh -c 'npm i -g yarn && yarn -v'

now, back home, i am unable to reproduce it, was there a faulty built in between yesterday and today?

sorry for the noise.