Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example from-docker : build fail : failed to compute cache key: "/yarn.lock" not found #33493

Closed
JulienCorb opened this issue Jan 20, 2022 · 8 comments · Fixed by #33695
Closed
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers

Comments

@JulienCorb
Copy link

JulienCorb commented Jan 20, 2022

What example does this report relate to?

from-docker

What version of Next.js are you using?

latest

What version of Node.js are you using?

node:16-alpine

What browser are you using?

chrome

What operating system are you using?

macOS

How are you deploying your application?

sudo docker build -t myappname .

Describe the Bug

trace :

[+] Building 0.8s (11/19)                                                                                                         
 => [internal] load build definition from Dockerfile                                                                         0.0s
 => => transferring dockerfile: 37B                                                                                          0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 34B                                                                                             0.0s
 => [internal] load metadata for docker.io/library/node:16-alpine                                                            0.7s
 => [internal] load build context                                                                                            0.0s
 => => transferring context: 4.03kB                                                                                          0.0s
 => [deps 1/5] FROM docker.io/library/node:16-alpine@sha256:2f50f4a428f8b5280817c9d4d896dbee03f072e93f4e0c70b90cc84bd1fcfe0  0.0s
 => CACHED [builder 2/5] WORKDIR /app                                                                                        0.0s
 => CACHED [runner 3/8] RUN addgroup -g 1001 -S nodejs                                                                       0.0s
 => CACHED [runner 4/8] RUN adduser -S nextjs -u 1001                                                                        0.0s
 => CACHED [deps 2/5] RUN apk add --no-cache libc6-compat                                                                    0.0s
 => CACHED [deps 3/5] WORKDIR /app                                                                                           0.0s
 => ERROR [deps 4/5] COPY package.json yarn.lock ./                                                                          0.0s
------
 > [deps 4/5] COPY package.json yarn.lock ./:
------
failed to compute cache key: "/yarn.lock" not found: not found

Expected Behavior

it should build the image with no error

To Reproduce

have Docker installed
run npx create-next-app --example with-docker myappname
run sudo docker build -t myappname .

NB : image build works when app gets created with yarn instead of npx

@JulienCorb JulienCorb added the bug Issue was opened via the bug report template. label Jan 20, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented Jan 20, 2022

The example is optimized to work with Yarn https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile

When building, it is trying to copy over the yarn.lock file, but it does not exist on your system.

We could add a small note about that in the docs: https://nextjs.org/docs/deployment#docker-image

Would you like to open a PR?

@balazsorban44 balazsorban44 added area: documentation examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers and removed bug Issue was opened via the bug report template. labels Jan 20, 2022
@JulienCorb
Copy link
Author

thank you @balazsorban44, yes I'll open a PR !

@fahmyfarahat
Copy link

Hi 👋 @JulienCorb, I can take this one if you didn't open PR.

@JulienCorb
Copy link
Author

Haven't done it yet, go ahead @fahmyfarahat ! thank you 😃

@balazsorban44 balazsorban44 linked a pull request Jan 26, 2022 that will close this issue
1 task
@balazsorban44
Copy link
Member

Heads up, there is already a PR for this at #33695 👍

@kodiakhq kodiakhq bot closed this as completed in #33695 Jan 27, 2022
@oelbaga
Copy link

oelbaga commented Feb 19, 2022

I have tested this. It still fails with the same error. yarn.lock isn't being created after you run
docker build -t nextjs-docker . The issue only happens if you use npx

npx create-next-app --example with-docker nextjs-docker

The OP's original issue persists.

Even if you create yarn.lock manually before running you run into another error: ERROR [deps 5/5] RUN yarn install --frozen-lockfile

@balazsorban44
Copy link
Member

Please check the Dockerfile in the example that is being cloned:

COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# If using npm with a `package-lock.json` comment out above and use below instead
# COPY package.json package-lock.json ./
# RUN npm ci

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants