Install Yarn In Docker Container

  • Before you start using Yarn, you'll first need to install it on your system. There are many different ways to install Yarn, but a single one is recommended and cross-platform: Install via npm. It is recommended to install Yarn through the npm package manager, which comes bundled with Node.js when you install it on your system.
  • Because there’s only one codebase inside the Docker container and the container is run under the non-root user node per best practice, I’ve chosen to put this.yarnrc file in the node user’s home directory. The only Yarn-related files that are not captured in the Docker image are yarn.lock and.pnp.js because their locations are not.

See Node install instructions.

ContainerContainer

Fantashit December 2, 2020 7 Comments on npm install yarn –global fails in docker container. Bug description. I’ve tried to install the latest yarn globally using lts/carbon npm. It’s failed with some permission denied message. As I see the version which has been tried to install is not released: 1.22.7.

Use Node image

Docker

Use the node image from Docker hub.

Containers

This includes Yarn already.

Install Yarn In Docker Container In Html

  • Dockerfile

Latest Node from APT

Use the ubuntu image from Docker hub.

APT already supports Node, but you’ll only get a stable version which will behind the latest versions. See the next section to get a newer version of Node.

  • Dockerfile
Install Yarn In Docker Container

Install Yarn In Docker Container Model

Node from Deb source

Similar to above, but instead of getting the Node version supported by APT (e.g. 10 or 12), you get a target version that you specify (like 14 or 16).

On the curl line, use setup_14.x or setup_16.x for example (using a literal letter x).

Based on Installation instructions in the Node docs, which covers Ubuntu and Debian. The docs don’t say that you need to run update after adding the souce.

  • Dockerfile

Yarn from APT

Set up a plain image then add Yarn to it using apt.

Install Yarn In Docker Container Box

  • Dockerfile

Notes:

  • DEBIAN_FRONTEND is set to avoid the flow to set region for tzdata.
  • It found I got errors consistently on apt update so switched to apt-get update.
  • Adding apt-utils is not neeeded, but prevents error when using debconf.
  • There is already an apt packaged called yarn which is unrelated to JavaScript, so be sure to remove it.
  • Install gnupg for apt-key to work on the curl line.