I can’t copy file from outsite of dockerfile’s folder.
I’m getting error from docker-compose build:
failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount196528245/target: lstat /var/lib/docker/tmp/buildkit-mount196528245/target: no such file or directory
ERROR: Service 'discovery' failed to build : Build failed
There is the folder structure
discovery
-docker
Dockerfile
-target
discovery.jar
This is Dockerfile
FROM openjdk:11
ARG JAR_FILE=../target/discovery.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
and this is my docker-compose file
services:
discovery:
build: ./discovery/docker
ports:
- 8761:8761
Thank in adance for help.
2
Answers
This is by design.
The Docker build context (a tarball sent to the Docker daemon along with the instructions in the Dockerfile) is computed from the directory you run
docker build
in.You’ll need to do
within
discovery
, with(not
..
) (or pass the corresponding--build-arg
).AS already pointed out in AKX answer, you cannot move outside the context (upwards). I just want to show that can build your app by providing the right parameters. Since you state that, you can’t go out of the docker folder.
The key is to use the parent directory discovery as context, but use the Dockerfile from the child directory docker. Note that this is relative to the build context when using compose.