Docker Yarn error

==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon  14.97kB
[+] Building 6.2s (8/13)
 => [internal] load remote build context                                            0.0s
 => copy /context /                                                                 0.0s
 => resolve image config for docker.io/docker/dockerfile:1                          0.4s
 => docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0  0.3s
 => => resolve docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a08176  0.0s
 => => extracting sha256:a47ff7046597eea0123ea02817165350e3680f75000dc5d69c9a31025  0.2s 
 => => sha256:39b85bbfa7536a5feceb7372a0817649ecb2724562a38360f4d6 8.40kB / 8.40kB  0.0s
 => => sha256:966d40f9ba8366e74c2fa353fc0bc7bbc167d2a0f3ad2420db8b9e63 482B / 482B  0.0s 
 => => sha256:dbdd11720762ad504260c66161c964e59eba06b95a7aa64a6863 2.90kB / 2.90kB  0.0s 
 => => sha256:a47ff7046597eea0123ea02817165350e3680f75000dc5d69c 11.55MB / 11.55MB  0.1s 
 => [internal] load metadata for docker.io/library/node:18.15.0-slim                0.1s
 => [base 1/3] FROM docker.io/library/node:18.15.0-slim@sha256:639e94182196dccc83a  3.2s
 => => resolve docker.io/library/node:18.15.0-slim@sha256:639e94182196dccc83a45224  0.0s 
 => => sha256:095c1ce1491a2109e1c41b6ec3ba3726564f7ba93bcae64187fc 1.37kB / 1.37kB  0.0s 
 => => sha256:9bea78a32dc7bfb874c53484dee9d885ab41fc80677c5e826b0e 6.84kB / 6.84kB  0.0s 
 => => sha256:26c5c85e47da3022f1bdb9a112103646c5c29517d757e95426 31.42MB / 31.42MB  0.4s 
 => => sha256:96da4c1974ec407e9c85ee9c418a567a28da4980460fa22ae124 4.18kB / 4.18kB  0.0s
 => => sha256:265a4d24e7df63a67c31cfa7fd56c9a89d006982d4e9a4e90d 46.06MB / 46.06MB  0.5s 
 => => sha256:2ac293a3f2e8157f3a118eabfdb6e4ff84d38800ac91d8659c38 2.76MB / 2.76MB  0.1s 
 => => sha256:6e7507789d867dd350c0703eae24110bffaacdc7d4f217e4cc759dd2 449B / 449B  0.0s 
 => => sha256:639e94182196dccc83a45224a10d2a3cb4139c0e3d05194b64d6 1.21kB / 1.21kB  0.0s 
 => => extracting sha256:26c5c85e47da3022f1bdb9a112103646c5c29517d757e95426f16e4bd  1.0s 
 => => extracting sha256:96da4c1974ec407e9c85ee9c418a567a28da4980460fa22ae124fba80  0.0s 
 => => extracting sha256:265a4d24e7df63a67c31cfa7fd56c9a89d006982d4e9a4e90df72967e  1.4s 
 => => extracting sha256:2ac293a3f2e8157f3a118eabfdb6e4ff84d38800ac91d8659c383bc77  0.1s 
 => => extracting sha256:6e7507789d867dd350c0703eae24110bffaacdc7d4f217e4cc759dd2e  0.0s 
 => [base 2/3] WORKDIR /app                                                         0.1s 
 => ERROR [base 3/3] RUN npm install -g yarn@1.22.19                                1.8s 
------
 > [base 3/3] RUN npm install -g yarn@1.22.19:
#8 1.825 npm ERR! code EEXIST
#8 1.826 npm ERR! path /usr/local/bin/yarnpkg
#8 1.828 npm ERR! EEXIST: file already exists
#8 1.828 npm ERR! File exists: /usr/local/bin/yarnpkg
#8 1.828 npm ERR! Remove the existing file and try again, or run npm
#8 1.828 npm ERR! with --force to overwrite files recklessly.
#8 1.830
#8 1.830 npm ERR! A complete log of this run can be found in:
#8 1.830 npm ERR!     /root/.npm/_logs/2023-05-06T01_19_57_474Z-debug-0.log
------
Error: failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c npm install -g yarn@$YARN_VERSION]: exit code: 1

FlyIo Dockerfile:

# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.15.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="NodeJS"

# NodeJS app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ARG YARN_VERSION=1.22.19
RUN npm install -g yarn@$YARN_VERSION


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
    apt-get install -y python-is-python3 pkg-config build-essential 

# Install node modules
COPY --link package.json yarn.lock .
RUN yarn install

# Copy application code
COPY --link . .



# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
CMD [ "yarn", "run", "start" ]

Two possible fixes:

  • Per the error message, you can add --force to the npm install line.
  • As it turns out, yarn version 1.22.19 is the base included with the node 18.15.0 image, so you can actually delete these two line.

Either way is fine

2 Likes

Thanks! I commented these two lines in Dockerfile and it solved the issue.

If I add --force, there is an error

=> ERROR [base 3/3] RUN npm install -g yarn@3.5.1 --force                      1.5s
------                                                                               
 > [base 3/3] RUN npm install -g yarn@3.5.1 --force:
#8 0.522 npm WARN using --force Recommended protections disabled.
#8 1.423 npm notice 
#8 1.424 npm notice New major version of npm available! 8.3.0 -> 9.6.6
#8 1.425 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.6.6>
#8 1.425 npm notice Run `npm install -g npm@9.6.6` to update!
#8 1.425 npm notice 
#8 1.427 npm ERR! code ETARGET
#8 1.428 npm ERR! notarget No matching version found for yarn@3.5.1.
#8 1.429 npm ERR! notarget In most cases you or one of your dependencies are requesting
#8 1.429 npm ERR! notarget a package version that doesn't exist.
#8 1.430 
#8 1.430 npm ERR! A complete log of this run can be found in:
#8 1.430 npm ERR!     /root/.npm/_logs/2023-05-11T15_22_00_103Z-debug-0.log
------
Error: failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c npm install -g yarn@$YARN_VERSION --force]: exit code: 1

Yarn version 3 is installed differently. I haven’t tried it myself yet, but it looks like the following command will work:

RUN corepack enable && corepack prepare yarn@3.5.1 --activate

I’ve opened Support Yarn v3. · Issue #17 · fly-apps/dockerfile-node · GitHub to track fixing the dockerfile that we generate.

1 Like

This issue has been closed, as yarn3 appears to be working.

@andrii give it a try by downloading the repo, and calling index.js from within your project directory.

It’s passing all the tests, and builds successfully in CI, but if you have any more issues please let us know.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.