EPERM errors when copying from cache to node_modules in Docker

Bug description

My builds have started failing in CircleCI, I am building a Docker image. The Dockerfile is the following (only copying until the failing line)

FROM node:12-alpine AS builder
WORKDIR /work

# Copy package manifests and other needed files for yarn install
COPY package.json /work/package.json
COPY app/package.json /work/app/package.json
COPY server/package.json /work/server/package.json
COPY packages/schemas/package.json /work/packages/schemas/package.json
COPY packages/db/package.json /work/packages/db/package.json

COPY yarn.lock /work/yarn.lock
COPY .yarnrc /work/.yarnrc
COPY yarn-offline-cache /work/yarn-offline-cache

RUN yarn install --offline

# Also tried various combinations of this
# RUN for i in 1 2 3; do yarn install --network-concurrency 1 --cache-folder /work/.yarn-cache; done

And my .yarnrc is

yarn-offline-mirror "./yarn-offline-cache"
yarn-offline-mirror-pruning true

# Also tried this
# child-concurrency 1

The error happens consistently at the yarn install stage.

What is the current behavior?
I get the following error output:

yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.1.3: The platform "linux" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "workspace-aggregator-a142b5cb-fa27-4c51-8d2a-c9c2e9e48c30 > @foxling/schemas > @graphql-codegen/typescript > @graphql-codegen/visitor-plugin-common > @graphql-tools/relay-operation-optimizer > relay-compiler@10.0.1" has incorrect peer dependency "graphql@^15.0.0".
warning "workspace-aggregator-a142b5cb-fa27-4c51-8d2a-c9c2e9e48c30 > @foxling/schemas > @graphql-codegen/typescript-react-apollo > @graphql-codegen/visitor-plugin-common > @graphql-tools/relay-operation-optimizer > relay-compiler@10.0.0" has incorrect peer dependency "graphql@^15.0.0".
error An unexpected error occurred: "EPERM: operation not permitted, copyfile '/work/.yarn-cache/v6/npm-@apollo-federation-0.20.0-59e084e73a0b5852d1de4da3bdafd5c94c757a83-integrity/node_modules/@apollo/federation/CHANGELOG.md' -> '/work/node_modules/@apollo/federation/CHANGELOG.md'".
info If you think this is a bug, please open a bug report with the information provided in "/work/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

It is usually always the same file, although I have seen some other filenames/packages also. @apollo/federation is the first package listed in the lockfile in case that matters.

I have tried reducing all kinds of concurrency in case it is a race condition, setting network-concurrency and child-concurrency to 1. I usually install using --offline but the same error happens if I leave that flag out.

It is strange to get permission-related errors, since all of these file operations happen inside Docker. I tried examining the Docker container after the build fails and all the files/folders exist and are readable/writable from the looks of it. Is there any way to get any further details on the EPERM error, i.e. if it is a read or write error?

What is the expected behavior?
For the installation to go through.

Steps to Reproduce
Sadly I can’t reproduce this even locally, it only happens in the docker build command on CircleCI. I have also opened a support ticket with them.

Environment

  • Node Version: Latest node:12-alpine docker image
  • Yarn v1 Version: 1.22.5
  • OS and version: Whatever CircleCI uses

Author: Fantashit

1 thought on “EPERM errors when copying from cache to node_modules in Docker

Comments are closed.