简体   繁体   中英

An error, "failed to solve with frontend dockerfile.v0"

I was trying to build my Docker image for my Gatsby application. Whenever I run the command docker build. -t gatsbyapp docker build. -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

I had experienced this issue after upgrading to the latest Docker Desktop version on Mac. Solved with the comment on this issue .

Solution: Don't use buildkit and it works for me.

export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

I had the same issue and all I had to do was to capitalize the Docker configuration filename:

dockerfile > didn't work

Dockerfile > did work

可能不是 OP 遇到的问题,但是我在尝试构建在Windows 子系统 for Linux (WSL) (Debian WSL2) 中运行的容器时遇到了这个问题,就在刚刚安装了Docker Compose之后,我所要做的就是关闭 ( Debian)终端并重新打开它,我的问题就解决了。

If you are seeing this issue it is not actually the real issue. The actual issue is nested in the error logs somewhere. To see the actual issue you need to run your build command like this:

DOCKER_BUILDKIT=0  docker build .

Notice the DOCKER_BUILDKIT=0 . That will make the build kit not hide the nested error. From there you should be able to google the correct solution.

This will also make the build look different in command line, but don't worry about that. Just look for the error.

If you use Docker for Windows you need to disable buildkit. It works for me.

Set buildkit option to false .

{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "features": {
    "buildkit": false
  }
}

Docker for Windows buildkit 选项

If you are using Docker Desktop, restarting Docker worked for me. TroubleshootRestart

I have the same issue.

Docker filename :

  • D ocker F ile - error
  • docker F ile - error
  • D ockerfile - work!

You need only one capitalized character.

In my case I was trying to copy over folder wp-content from my current directory, inside the Docker image I was building. Like so:

FROM wordpress:latest

# Copy wp-content
COPY ./wp-content/ ./var/www/html/wp-content/

However, I noticed that I had a .dockerignore file, which explicitly was told to ignore wp-content .

When I removed wp-content/ from .dockerignore it worked fine.

Disable the macOS v11 (Big Sur) virtualization framework:

在此处输入图像描述

If you are using Docker Desktop for Mac or Windows, you might have to also disable it in your 'Docker Engine' JSON configuration.

Docker Desktop → SettingsDocker Engine → change the "features": { buildkit: true} to "features": { buildkit: false}.

In my case, I had an extra space after "." in the context option:

docker build -t myapp .[EXTRA_SPACE_HERE]

Make sure your .dockerignore doesn't match your file.

A pattern sometimes used with .dockerignore is to add a wildcard to it and exclude the specifically expected file to the context with !filename syntax. EG:

*
!Cargo.toml
!Cargo.lock
!src
!setup.py
!README.md
!project
!requirements
__pycache__

If you later try to use a file in Dockerfile it will match the wildcard and not be present in the context. Add an exception to the new file or remove the wildcard to fix this.

I don't remember where exactly I read this, but if you are using WSL2 and receive that error, then delete the Docker configuration file in your WSL2 home folder and try to rebuild your image.

That is if you have already checked your file names and reconfirmed that everything is named correctly ( Dockerfile , .dockerignore , etc.)

WSL2 Ubuntu :

rm ~/.docker/config.json

In my case

failed to solve with frontend dockerfile.v0: failed to create LLB definition: no build stage in current context

was caused by setting ENV before FROM. Probably this is not allowed for some Dockerfile instructions. After moving ENV right after FROM the error is gone.

Had a typo,

FROM apline:3.7 instead of FROM alpine:3.7

I faced the issue due to VPN connectivity.

All I had to do was set a manual proxy in the Docker Desktop PROXIES section:

在此处输入图像描述

当我用完磁盘空间时,我遇到了这个问题,大概是由于我戏弄和调整我的 Dockerfile 时积累的大量图像层缓存而加剧了这个问题。

I had to set "credsStore": "" in my ~/.docker/config.json ... . It was previously set to credentials.exe .

In WSL2 ddev start fails at docker-credential-desktop.exe, "error listing credentials" #2342

尝试使用这个简单的解决方案,将您的dockerfile 命名为不带扩展名的 Dockerfile。

In my case, I had two problems:

  1. I missed the . in the end of the command that gives the context option, and
  2. I have a ".txt" extension in the file name of the Dockerfile.

After these two adjustments, all worked as expected.

Sometimes this kind of error comes from a stupid syntax error... In my case I modified a Dockerfile and removed some environment variables, but forgot to take off the backslash from the last line...

    WORDPRESS_HTTPS_PORT="8443" \
    WORDPRESS_HTTP_PORT="8080" \
    WORDPRESS_SKIP_INSTALL="yes" \ <-- to be removed

EXPOSE 8080 8443
USER 0

For me the following was the error:

failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to do request: Head https://registry-1.docker.io/v2/library/postgres/manifests/13-alpine : net/http: TLS handshake timeout

I am using WSL2 in Windows 10 and Docker Desktop and I got this issue after updating the Docker Desktop to version 3.5.

I fixed the issue by enabling the WSL integration with additional distributions .

To enable it:

Open Docker Desktop in Windows and go to settingsResourcesWSL IntegrationEnable integration with additional distributions and enable it for the Ubuntu application that you installed.

I had the same error, but by moving the Dockerfile out of the sub-folder and into the root folder of my application. It fixed the error message.

如果您使用 Docker for Windows,请确保将 Docker 引擎设置为与您要构建的映像匹配的模式(Windows / Linux)。

I had the same issue while building a Docker image through Visual Studio 2019 . My Docker file had a name like Dockerfile.

Dockerfile > didn't work

dockerfile > did work

如果您的 docker 文件位于与Dockerfile不同名称的不同路径中,您可以运行

docker build -t build_tag_name -f './path/to/dockerfile/exampledockerfile' .

I was trying to build my Docker image for my Gatsby Application. Whenever I run the command docker build . -t gatsbyapp docker build . -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

Chiming in with another possibility that happened to me: If you're using build stages, make sure that you have the right stage names throughout.

I had a stage defined with

FROM zzz AS development

that was later used for another stage

FROM development AS yyy

On a whim I changed development to dev , but only in the first instance. So the latter one was still FROM development while the former was AS dev .

Odd how arcane the error message is for a such a minor mistake... You'd think they could just have the error message say "couldn't find development " or something.

Make sure that you are using the same platforms, eg if you build the first image (my-custom-service) with

FROM --platform=linux/amd64 node:14

then you need to add the --platform to other Dockerfile s that use the baseimage of the first:

FROM --platform=linux/amd64 my-custom-service

I ran into this problem using WSL2 Ubuntu, and I fixed it by changing the permissions of the Dockerfile.

When I set up WSL2 on my computer I copied some of my files (including the Dockerfile) directly from Windows into the Ubuntu root folder , which apparently results in files with blank permissions:

---------- 1 user user 10M Jan 1 00:00 Dockerfile

To fix it I ran chmod 644 Dockerfile :

-rw-r--r-- 1 user user 10M Jan 1 00:00 Dockerfile

And after that Docker was able to build the image without any further issue.

In my case, this was because of the under-expressed use cases from documents. almost all examples tell you to use . and Dockerfile (capital D) but mostly does not tell explicitly how to customize.

docker image build --tag any_image_tag --file any_file_name path_to_your_context_folder

This one is better in my opinion, and I hope will help those coming here. any_file_name is really any file name with build instructions in it, "dockerfile" in it is not needed but helps to identify and give full path if it differs from context folder. path_to_your_context_folder is basically where your work resides, such as a web app.

for example, the following is my current test in windows where COPY . /app COPY . /app uses context folder as the . :

docker image build --tag nested_image --file C:\WorkSpace\myapp\dockerfiles\any_file_name C:\WorkSpace\myapp\contextfiles\

PS: The topic really has interesting answers to the same problem but by lots of exotic causes. mine is just a side note to a hidden-in-plain-sight problem.

In my case, I had 2 images, and I was copying from the same image. My specific error was: failed to solve: failed to solve with frontend dockerfile.v0: failed to create LLB definition: circular dependency detected on stage: kubexit

FROM karlkfi/kubexit:latest AS kubexit
COPY --from=kubexit /bin/kubexit /bin/

FROM maven:3.8-jdk-11-slim AS build

So it was a circular reference. The fix:

FROM karlkfi/kubexit:latest AS kubexit

FROM maven:3.8-jdk-11-slim AS build
COPY --from=kubexit /bin/kubexit /bin/

[Solved for me]

I'm using MacBook M1 Chip, and why it was giving issue because I was using image which support linux/amd64 and my system arch is arm64 .

So make sure run the compatible image based on your device.

我的问题是由于使用VPN。

For Me

I Opened Docker Desktop->open settings->Docker Engine->

{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "features": {
    "buildkit": false
  }
}

Here My default value of buildkit is true -> i changed to false and restart the docker engine

that worked for me

With the docker desktop this issue is usually solved by adding -f option. for example: Let your docker file is placed at c:\Dockerfile.txt

you can run the following command to build the image

docker build -f "c:\Dockerfile.txt"

I was trying to build my Docker image for my Gatsby Application. Whenever I run the command docker build . -t gatsbyapp docker build . -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

If you are using Windows Subsystem for Linux (WSL), check if Docker is running before you launch the window. If you have started Docker after starting the window. Then Just restart your terminal. And it should work if your file is correct.

I was trying to build my Docker image for my Gatsby Application. Whenever I run the command docker build . -t gatsbyapp docker build . -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

I was trying to build my Docker image for my Gatsby Application. Whenever I run the command docker build . -t gatsbyapp docker build . -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

I was trying to build my Docker image for my Gatsby Application. Whenever I run the command docker build . -t gatsbyapp docker build . -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

I was trying to build my Docker image for my Gatsby Application. Whenever I run the command docker build . -t gatsbyapp docker build . -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

I was trying to build my Docker image for my Gatsby Application. Whenever I run the command docker build . -t gatsbyapp docker build . -t gatsbyapp , it gives me an error:

failed to solve with frontend dockerfile.v0: failed to build LLB:
failed to compute cache key: "/.env" not found: not found

Meanwhile my Dockerfile is shown below:

FROM node:13

WORKDIR /app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

COPY .env .

EXPOSE 8000

CMD ["gatsby","develop","-H","0.0.0.0"]

Specify the proxy server by setting the HTTP_PROYY and HTTP_PROXYS environment variables.

Example:

http_proxy=http://username:password@proxy.example.com:8080
https_proxy=http://username:password@proxy.example.com:8080

As far as I can see, this error can have many reasons.

In my case, there were two errors: (1) in the Dockerfile: the # syntax = ***** line was incorrectly spelled out and (2) in file docker_compose.yaml , the web / build: * line was pointing to the wrong directory.

I was helped by reading the Dockerfile documentation and taking a break to regain attention.

I've had this issue/error before when I had a script that I used to build multiple Dockerfiles and where one of the Dockerfiles was commented out. Once I uncommented the Dockerfile and run the script again it worked fine for me.

In case you have a similar project structure

├── docker                   
│   │
│   ├── app
│   │   └── Dockerfile
│   └── mlflow  
│       └── Dockerfile
│
└── docker-compose.yml

you might be missing to specify the build: context in the docker-compose.yml

version: '3'

services:

  mlflow:
    build: 
      context: ./
      dockerfile: ./docker/mlflow/Dockerfile
    container_name: ml_app_mlflow
    volumes:
      - ./db:/db
    ports:
      - 5000:5000

In case you previously executed docker buildx install , your docker command is aliased to docker buildx , which is based on Docker Buildkit , which is currently not supported (sadly) for Windows containers.

To remove the alias, execute the following command:

docker buildx uninstall

I hope that will save time to people like me, who forgot about this alias

对我来说,我发现我试图从错误的目录构建。

就我而言,我与 dockerfile 本身不在同一个目录中

yet another possibility: I was using linux based containers on Windows 10 for WSL when trying to build a Dockerfile with a windows 10 servercore image. In the system tray, Right click Docker Desktop and select Switch to Windows containers ...

I solved this problem by just adding sudo (Ubuntu) at the head of the build command. For example:

sudo docker build --tag somename .

All it took for me was adding --no-cache as an argument to the build.

If you are using any new features that are not supported in v0 Dockerfile (like multiple build contexts), you need to specify Dockerfile version at the start of Dockerfile

For example in Dockerfile , first line would be:

#syntax=docker/dockerfile:1.4

I had the same issue while using visual studio 2022. The problem was that visual studio 2022 make a logical directory structure which was different from the physical directory structure. So the file was physically not present at the location where visual studio 2022 was showing.

Once the correct location was specified, it works fine.

I did not have to change DOCKER_BUILDKIT=0 or any settings. But used -f option to specify the docker file.

None of the other answers worked for me. In my case the problem was I had some permission issues with docker in CLI and rather than fixing it I was just using sudo . So I fixed those permission issues (in the ~/.docker/buildx folder) and ran docker without sudo and it worked.

就我而言,我必须卸载 Astrill VPN。

I faced this issue at today. My problem is I created and fill Dockerfile but didn't save changes in Dockerfile, I try CTRL + S and try again build, worked for me ))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM