Reputation: 4004
I was trying to build my Docker image for my Gatsby application. Whenever I run the command 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"]
Upvotes: 389
Views: 751660
Reputation: 46
In my case the issue was with nswagger. I forgot to upgrade the nswagger runtime and also update the msbuild nswagger command.
Upvotes: 0
Reputation: 2897
If you are using Docker dind for CI purposes, this issue happened for me when I used the stable-dind
tag and my image required Docker Buildkit. Using the regular dind
tag solved it for me.
Upvotes: 0
Reputation: 450
Is my case it was because the applications defined in a docker-compose file did not have individual Dockerfiles, but was sharing the same Dockerfile. After defining in docker-compose.yml:
build:
dockerfile: <RELATIVE_PATH_TO_THE_DOCKER_FILE>
In each of the apps build section, it is building correctly.
Upvotes: 0
Reputation: 1770
This is simple actually, if you will read full error solution is there only:
error says: failed to solve with frontend dockerfile.v0: failed to read dockerfile
, it means it is looking for docker file which is named as dockerfile
, so chances maybe you renamed or have created your Docker file with some different name.
Upvotes: -2
Reputation: 22146
I had a symlink
to the directory I was running docker build
from. Make sure you cd
into the actual path of the directory your Dockerfile
is in, and not run it from a symlink
path.
Upvotes: 0
Reputation: 1142
I got a similar output. Turns out I exported USER=''
in my .zshrc
. Exporting a value there fixed the issue: USER='yourname'
[...]
Failed to fire hook: while creating logrus local file hook: user: Current requires cgo or $USER set in environment
[2023-02-27T11:20:07.698673000Z][docker-credential-desktop][F] user: Current requires cgo or $USER set in environment
[common/pkg/paths.Home()
[ common/pkg/paths/paths.go:105 +0x54
[common/pkg/paths.Container()
[ common/pkg/paths/user_darwin.go:30 +0x1d
[common/pkg/paths.Data()
[ common/pkg/paths/paths_darwin.go:27 +0x19
[+] Building 1.0s (3/3) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR [internal] load metadata for docker.io/library/node:16-buster 0.8s
------
> [internal] load metadata for docker.io/library/node:16-buster:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: rpc error: code = Unknown desc = error getting credentials - err: exit status 1, out: ``
Upvotes: 0
Reputation: 179
All it took for me was adding --no-cache
as an argument to the build.
Upvotes: 1
Reputation: 567
The issue was fixed for me after removing the "LABEL" Instruction & its Argument in my Dockerfile
LABEL maintainer="[email protected]"
Upvotes: 1
Reputation: 3304
If you use Docker for Windows you need to disable buildkit from Docker Engine in Settings. It works for me and solved my error
Set buildkit option to false.
{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false,
"features": {
"buildkit": false
}
}
Upvotes: 138
Reputation: 1452
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.
Upvotes: 1
Reputation: 215
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.
Upvotes: 0
Reputation: 89
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"
Upvotes: 1
Reputation: 21098
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
Upvotes: 2
Reputation: 398
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
Upvotes: 1
Reputation: 1502
I solved this problem by just adding sudo (Ubuntu) at the head of the build command. For example:
sudo docker build --tag somename .
Upvotes: 1
Reputation: 2994
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 they mostly do 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 it 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 it helps to identify and give the full path if it differs from the context folder. path_to_your_context_folder
is basically where your work resides, such as a web application.
For example, the following is my current test in windows where COPY . /app
uses the 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.
Upvotes: 5
Reputation: 652
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...
Upvotes: 0
Reputation: 69
It was solved for me
I was using a MacBook Air (M1) and had an issue, because I was using an image which supported linux/amd64 and my system architecture was arm64.
So make sure to run the compatible image based on your device.
Upvotes: 5
Reputation: 131
In my case I was not in the same directory as the dockerfile itself.
Upvotes: 1
Reputation: 1651
In case your Docker file is in a different path with a different name than Dockerfile you can run
docker build -t build_tag_name -f './path/to/dockerfile/exampledockerfile' .
Upvotes: 3
Reputation: 6667
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
Upvotes: 1
Reputation: 3446
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.
Upvotes: 1
Reputation: 211
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
Upvotes: 20
Reputation: 159
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
Upvotes: 2
Reputation: 596
Try with this simple solution, name your dockerfile like this Dockerfile with no extension.
Upvotes: 5
Reputation: 3286
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
Upvotes: 0