Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install yarn on docker FROM node:9.11.2-alpine?

Tags:

docker

yarnpkg

my docker

 - FROM node:9.11.2-alpine
 - RUN apk add yarn

And error:

yarn (missing):    required by: world[yarn]
[91mWARNING: Ignoring APKINDEX.84815163.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.24d64ab1.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
The command '/bin/sh -c apk add yarn' returned a non-zero code: 1

[Sat Jun 23 2018 16:04:57 GMT+0100 (GMT Daylight Time)] ERROR Child process exited with code 1

I can't understand why is so hard to add Yarn to a docker. I tried so many things and all fails in some ways or another.

Until yesterday I was able to install Yarn on my docker with RUN npm install -g yarn but this morning stopped working with error:

request to https://registry.npmjs.org/yarn failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443

Some of the things I've tried:

  • No results for "inurl:yarnpkg.com docker" in google
  • https://github.com/mhart/alpine-node/issues/65

Edit one day after:

Now when I do yarn install I'm getting getaddrinfo EAI_AGAIN registry.yarnpkg.com:443 errors on every package.

looks like restarting docker fixes it. Also more info at https://development.robinwinslow.uk/2016/06/23/fix-docker-networking-dns/

like image 439
Totty.js Avatar asked Jun 23 '18 15:06

Totty.js


3 Answers

RUN set -eux \
    & apk add \
        --no-cache \
        nodejs \
        yarn
like image 81
josuedjh Avatar answered Nov 11 '22 11:11

josuedjh


As dumb as it sounds, looks like yarn is already installed in this docker version of node. So there is no need to install yarn at all.

Anyway not sure why RUN npm install -g yarn stopped working from one day to another.

like image 29
Totty.js Avatar answered Nov 11 '22 11:11

Totty.js


The latest yarn package is only available in the edge repository. This means, you should install it as follows (including the latest nodejs version):

RUN apk --no-cache add nodejs yarn --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
like image 37
Remigius Stalder Avatar answered Nov 11 '22 10:11

Remigius Stalder