Dockerfile Build Error: The system cannot find the path specified - docker

C:\kafka> docker build Dockerfile
[+] Building 0.0s (1/2)
=> ERROR [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 63B 0.0s
------
> [internal] load build definition from Dockerfile:
------
failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from sender: walk Dockerfile: The system cannot find the path specified.
Above is an example of the error I am getting and the command run.
My Dockerfile is named "Dockerfile" as I have read on many answers but still no resolve.
My Dockerfile is also within the directory I am in.

To build a docker image:
cd /path/where/docker_file/lives
docker build .
Above is same as:
docker build -f Dockerfile .
You need to specify Dockerfile name only if it is not default:
cd /path/where/docker_file/lives
docker build -f Dockerfile.modified .

Related

How to run a Cenos7 docker image on an ARM based Mac

I am tring to create a Dockerfile to run CentOS. One of the host systems needing to run this container is an ARM based (m1) Mac. These are the two files I have created so far.
# Dockerfile
FROM centos:7
# docker-compose.yml
version: "3.9"
services:
genesis:
build: .
When trying to run/build this cointainer I get the following error
Building genesis
[+] Building 0.9s (4/4) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 77B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR [internal] load metadata for docker.io/library/centos:7 0.8s
=> [auth] library/centos:pull token for registry-1.docker.io 0.0s
------
> [internal] load metadata for docker.io/library/centos:7:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: rpc error: code = Unknown desc = failed to fetch oauth token: Get "https://auth.docker.io/token?scope=repository%3Alibrary%2Fcentos%3Apull&service=registry.docker.io": read tcp 192.168.1.209:64469->3.228.155.36:443: read: software caused connection abort
ERROR: Service 'genesis' failed to build : Build failed
After some google searching and answers on stack overflow it looks like the issue is something to do with the architecture difference between the containers and the host. I have tried setting the dockerfile to
FROM --platform=aarch/arm centos:7
and
FROM --platform=linux/amd64 centos:7
but neither of these work, and they're returning the same error as before. I have also tried specifying the platform in the docker-compose file too but that didn't work either.
Interestingly I did seem to have it working when I use the command in the shell
$ docker run --rm -it --platform=linux/amd64 centos:7 sh
but I need to have it working in the dockerfile as I need to then have more setup in the dockefile
Docker isn't a virtual machine, so there are some limitations.
Your application is for Linux, but you appear to be trying to run it from macOS?
Does your FROM lines specify a version of Linux?
If so, you need a build a new container of binaries native to macOS and avoid using Linux containers in your FROM lines.

Building docker image failing when loading metadata

Im trying to create a docker image using my Dockerfile. I have no prior experience with Docker so I cant really decribe the problem better. I was able to do this yesterday without problems, but I deleted the image and now I cant recreate it.
My Dockerfile
FROM bitnami/spark
USER root
RUN pip install unidecode
RUN curl https://repo1.maven.org/maven2/com/databricks/spark-xml_2.12/0.13.0/spark-xml_2.12-0.13.0.jar --output /opt/bitnami/spark/jars/spark-xml_2.10-0.2.0.jar
ENV PYTHONPATH=$SPARK_HOME/python:$SPARK_HOME/python/lib/py4j-0.10.9-src.zip:$PYTHONPATH
Im trying to create docker image by this command docker build -t imagename .
I am in the same directory as Dockerfile, so thats not the issue.
This is the output I get when I run the command above.
[+] Building 32.0s (3/3) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 38B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR [internal] load metadata for docker.io/bitnami/spark:latest 31.8s
------
> [internal] load metadata for docker.io/bitnami/spark:latest:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize:
rpc error: code = Unknown desc = failed to fetch anonymous token:
Get "https://auth.docker.io/token?scope=repository%3Abitnami%2Fspark%3Apull&service=registry.docker.io":
dial tcp 54.85.56.253:443: i/o timeout
Restarting docker helped me to fix this.
Reinstalling docker helped to fix this problem

Docker Go image: starting container process caused: exec: "app": executable file not found in $PATH: unknown

I have been reading a lot of similar issues on different languages, none of them are Go.
I just created a Dockerfile with the instructions I followed on official Docker hub page:
FROM golang:1.17.3
WORKDIR /go/src/app
COPY . .
RUN go get -d -v ./...
RUN go install -v ./...
CMD ["app"]
This is my folder structure:
users-service
|-> .gitignore
|-> Dockerfile
|-> go.mod
|-> main.go
|-> README.md
If anyone needs to see some code, this is how my main.go looks like:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
I ran docker build -t users-service .:
$ docker build -t users-service .
[+] Building 5.5s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 154B 0.1s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/golang:1.17.3 3.3s
=> [auth] library/golang:pull token for registry-1.docker.io 0.0s
=> [1/5] FROM docker.io/library/golang:1.17.3#sha256:6556ce40115451e40d6afbc12658567906c9250b0fda250302dffbee9d529987 0.3s
=> [internal] load build context 0.1s
=> => transferring context: 2.05kB 0.0s
=> [2/5] WORKDIR /go/src/app 0.1s
=> [3/5] COPY . . 0.1s
=> [4/5] RUN go get -d -v ./... 0.6s
=> [5/5] RUN go install -v ./... 0.7s
=> exporting to image 0.2s
=> => exporting layers 0.1s
=> => writing image sha256:1f0e97ed123b079f80eb259dh3e34c90a48bf93e8f55629d05044fec8bfcaca6 0.0s
=> => naming to docker.io/library/users-service 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Then I ran docker run users-service but I get that error:
$ docker run users-service
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "app": executable file not found in $PATH: unknown.
I remember I had some troubles with GOPATH environment variable in Visual Studio Code on Windows, maybe it's related... Any sugguestions?
The official Docker documentation has useful instructions for building a Go image: https://docs.docker.com/language/golang/build-images/
In summary, you need to build your Go binary and you need to configure the CMD appropriately, e.g.:
FROM golang:1.17.3
WORKDIR /app
COPY main.go .
COPY go.mod ./
RUN go build -o /my-go-app
CMD ["/my-go-app"]
Build the container:
$ docker build -t users-service .
Run the docker container:
$ docker run --rm -it users-service
Hello, World!
Your "app" executable binary should be available in your $PATH to call globally without any path prefix. Otherwise, you have to supply your full path to your executable like CMD ["/my/app"]
Also, I recommend using an ENTRYPOINT instruction. ENTRYPOINT indicates the direct path to the executable, while CMD indicates arguments supplied to the ENTRYPOINT.
Using combined RUN instructions make your image layers minimal, your overall image size becomes little bit smaller compared to using multiple RUNs.

Can't build dockerfile with Pulumi

I'm trying to build a docker file with Pulumi. I have the following Pulumi code
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
imageName := "server"
_, err = docker.NewImage(ctx, imageName, &docker.ImageArgs{
ImageName: pulumi.Sprintf("gcr.io/gadic-310112/%s:latest", imageName),
SkipPush: pulumi.Bool(true),
Build: &docker.DockerBuildArgs{
Dockerfile: pulumi.String("Dockerfile"),
},
})
if err != nil {
return err
}
}
}
However, when I run pulumi preview I get the following error:
Diagnostics:
pulumi:pulumi:Stack (server-prod):
error: program failed: docker build -f Dockerfile . -t gcr.io/gadic-310112/server:latest failed with error: exit status 1
exit status 1
error: an unhandled error occurred: program exited with non-zero exit code: 1
docker:image:Image (server):
error: #1 [internal] load build definition from Dockerfile
#1 sha256:921a08a3c227abd8c3811effc689fa5319db237c32a4adf2b255007a51af9ef8
#1 transferring dockerfile: 2B 0.0s done
#1 DONE 0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount052159980/Dockerfile: no such file or directory
What's interesting is that it seems Pulumi is running docker build -f Dockerfile . -t gcr.io/gadic-310112/server:latest under the hood. And when I run that from my terminal it succeeds without any error.
❯❯❯ docker build -f Dockerfile . -t gcr.io/gadic-310112/server:latest
[+] Building 11.3s (16/18)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.87kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
....
It seems that Pulumi might be using a different working directory than the place where it's getting invoked from. Is that possible? Is there something else that might be going on?
I've noticed that if I don't include a Dockerfile in the DockerBuildArgs then the command generated by pulumi is docker build -f . -t gcr.io/gadic-310112/server:latest which is definitely incorrect. If I execute that command locally I get the following:
❮❮❮ docker build -f . -t gcr.io/gadic-310112/server:latest
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
EDIT: I also tried passing the absolute path to the folder containing my Dockerfile as the Context of the BuildArgs
Build: &docker.DockerBuildArgs{
Dockerfile: pulumi.String("Dockerfile"),
Context: pulumi.String("/Users/paymahn/gadic/server"),
},
and this still gets the same error as before, even though the underlying docker build command has an absolute path:
Diagnostics:
docker:image:Image (server):
error: #1 [internal] load build definition from Dockerfile
#1 sha256:16f11ab26c775f06385c0fde07864ed70b428d13662aa2be42823751fb5143f4
#1 transferring dockerfile: 2B 0.0s done
#1 DONE 0.1s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount684750851/Dockerfile: no such file or directory
pulumi:pulumi:Stack (server-prod):
error: program failed: docker build -f Dockerfile /Users/paymahn/gadic/server -t gcr.io/gadic-310112/server:latest failed with error: exit status 1
exit status 1
error: an unhandled error occurred: program exited with non-zero exit code: 1
EDIT 2: Here's the layout of my files
/Users/paymahn/gadic/server/
infra/
main.go # this is the go program that pulumi runs
src/ # this is where the source code for my server lives
Dockerfile
Pulumi.yaml
Pulumi.prod.yaml # the pulumi stack config
go.sum
go.mod
.git/ # this is the root of my git repository
Your Pulumi projects builds inside your infra directory, not in the folder your Pulumi.yaml is in.
The Pulumi provider needs to know the path of the Dockerfile using the docker build context (more info about these here)
Adding the context should fix this:
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
imageName := "server"
_, err = docker.NewImage(ctx, imageName, &docker.ImageArgs{
ImageName: pulumi.Sprintf("gcr.io/gadic-310112/%s:latest", imageName),
SkipPush: pulumi.Bool(true),
Build: &docker.DockerBuildArgs{
Dockerfile: pulumi.String("Dockerfile"),
Context: "../", # note I'm adding the context here
},
})
if err != nil {
return err
}
}
}

How do I build a dockerfile if the name of the dockerfile isn't Dockerfile?

I am able a build a Dockerfile like
docker build -t deepak/ruby .
But for a Dockerfile which is not named Dockerfile
# DOCKER-VERSION 0.4.8
FROM deepak/ruby
MAINTAINER Deepak Kannan "deepak#example.com"
RUN ./bin/rails s
let us say it is called Dockerfile.app
which we build with
docker build -t deepak/app Dockerfile.app
then i get the error
Uploading context 0 bytes
Error build: EOF
EOF
Notice there is a dot . at the end of both commands.
docker build -f MyDockerfile .
Or with a tag:
docker build -t mysuperimage -f MyDockerfile .
This Works
docker build -t doronaviguy/helloworld -f SomeDockerFile .
Docker build Documentation
The last parameter to docker build is the build path, when you put . it means this is the path where you will find the Dockerfile. When you change it to Dockerfile.app it will then try and look for Dockerfile.app/Dockerfile, which isn't correct.
I'm not sure if it will still work, but you used to be able to do this.
$ docker build -t deepak/app - < Dockerfile.app
Try that and see if it helps, if not, maybe open a docker issue to add this feature back in, or update the documentation on how to use a Dockerfile with a different name.
More info here: http://docs.docker.io/en/latest/commandline/command/build/
Try dockerfeed. It uses the docker feature to build a context via stdin. I wrote the script to address exactly your problem I was facing myself.
To replace a Dockerfile with a different one you do it like this:
dockerfeed -d Dockerfile.app . | docker build -t deepak/ruby -
And voilà. Dockerfeed is doing the same as docker build. It packs the source with its Dockerfile but lets you swap out the old Dockerfile with the desired one. No files are created in the process, no source is changed. The generated tar archive is piped into docker, which in turn sends it down to the docker daemon.
Update:
This was a valid answer in the old days when there was no -f switch available. With docker version 1.5 this option was introduced. Now you can build provide a different Dockerfile like this:
docker build -f other-Dockerfile .
This should work,
docker build -t <tag-name> -f <file-name> .
You can acheive this also using docker-compose.
In your docker-compose.yml under the build section, you can specify the directory in which you store your dockerfile and its alternate-name as follow :
build:
context: "/path/to/docker/directory"
dockerfile: "dockerfile-alternate-name"
docker-compose
Windows User should try below command:
docker build -f absolute_docker_file_path dot
for example :
docker build -f D:\Code\core-api\API_TEST.Dockerfile .
If you have multiple Dockerfile's, as could be the case in large projects, you could specify the respective fully-qualified Dockerfile to use.
docker build -t swagger_local -f /Users/123456/myrepos/storage/services/gateway/swagger/Dockerfile .
The command when run from /Users/123456/myrepos/storage creates a swagger_local image using the Dockerfile in a child project (services/gateway in my case )
My case is in the /tmp directory and there are a lot of files and docker try with others files althought I pass the -f <Dockerfile.foo>
The most clean and easy (for me) solution is (intead the dockerfeed from above answers):
cat DockerFile.debian.foo | docker build -t debian.foo -
Let assume that you have successfully install docker toolbox including docker-compose and docker-machine. This is my docker-compose.yml
version: '2'
services:
web: ./www/python
ports:
- "5000:5000"
And this is under Dockerfile
FROM python:3.4-alpine
ADD ./www/python /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
Make sure those files located precisely under root folder. When you run docker-compose up then you are going to build image for web.
For me it worked once I put the entire path in the file option:
(meta_learning) brandomiranda~ ❯ docker build -f ~/iit-term-synthesis/Dockerfile_arm -t brandojazz/iit-term-synthesis:test_arm ~/iit-term-synthesis/
[+] Building 43.8s (9/28)
=> [internal] load build definition from Dockerfile_arm 0.0s
=> => transferring dockerfile: 2.59kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/continuumio/miniconda3:latest 0.0s
=> [ 1/24] FROM docker.io/continuumio/miniconda3 0.0s
=> CACHED https://api.github.com/repos/IBM/pycoq/git/refs/heads/main 0.0s
=> [ 2/24] RUN apt-get update && apt-get install -y --no-install-recommends ssh git m4 libgmp-dev opam wget ca-ce 14.9s
=> [ 3/24] RUN useradd -m bot 0.2s
=> [ 4/24] WORKDIR /home/bot 0.0s
=> [ 5/24] ADD https://api.github.com/repos/IBM/pycoq/git/refs/heads/main version.json 0.0s
=> [ 6/24] RUN opam init --disable-sandboxing 28.6s
=> => # [ocaml-base-compiler.4.14.0] downloaded from cache at https://opam.ocaml.org/cache
=> => # <><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
=> => # ∗ installed base-bigarray.base
=> => # ∗ installed base-threads.base
=> => # ∗ installed base-unix.base
=> => # ∗ installed ocaml-options-vanilla.1
this failed for me:
(meta_learning) brandomiranda~ ❯ docker build -f Dockerfile_arm -t brandojazz/iit-term-synthesis:test_arm ~/iit-term-synthesis/
[+] Building 0.0s (1/2)
=> ERROR [internal] load build definition from Dockerfile_arm 0.0s
=> => transferring dockerfile: 40B 0.0s
------
> [internal] load build definition from Dockerfile_arm:
------
failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from sender: open .Trash: operation not permitted

Resources