Below is the Dockerfile
:
FROM golang:1.14.10
MAINTAINER xyz
COPY ~/go/bin/product-api /go/bin/product-api
COPY ~/go/bin/swagger /go/bin/swagger
ENTRYPOINT ["/go/bin/product-api"]
on docker build -t cloud-native-product-api:1.0.0 .
, gives error:
Step 3/5 : COPY ~/go/bin/product-api /go/bin/product-api
COPY failed: stat /var/lib/docker/tmp/docker-builder398080099/~/go/bin/product-api: no such file or directory
I think the image build process takes /var/lib/docker/tmp/docker-builder398080099
as workspace and refer from that path.
How to copy files from specific folder of local machine into Docker image?
It seems that docker build won't overwrite a file it has previously copied. I have a dockerfile with several copy instructions, and files touched in earlier COPY directives don't get overwritten by later ones. After building this, $BASE/config/thatfile. yml contains the contents of file1.
It turns out that you cannot include files outside Docker's build context. However, you can copy files from the Dockerfile's parent directory.
The key thing you are missing is the build's context, relevant from the COPY part of the docs:
The path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
https://docs.docker.com/engine/reference/builder/#copy
Description of "context" here.
https://docs.docker.com/engine/reference/commandline/build/
But essentially, when you say "docker build directory-with-docker-file" COPY only sees files in (and below) the directory with the Dockerfile.
What you probably want to do is compile "swagger" during the docker build, and then put it in the path you want.
A key thing to remember is that a Dockerfile is generally meant to be reproducible such that if you run docker build on ten different hosts, the exact same image will be produced. Copying files from arbitrary locations on the host wouldn't lead to that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With