docker-compose.yml:
version: '3'
services:
service:
build:
context: .
args:
- SOME_PATH=/mnt/some/absolute/path
# or
# - SOME_PATH=${ENVIRONMENT_VARIABLE_CONTAINING_ABSOLUTE_PATH}
# or
# - ENVIRONMENT_VARIABLE_CONTAINING_ABSOLUTE_PATH
Dockerfile:
...
ARG SOME_PATH
COPY ${SOME_PATH:-./out}/app /app # SOME_PATH somehow becomes a relative path (e.g. mnt/some/absolute/path)
# Produces error: Service 'service' failed to build: lstat mnt/some/absolute/path/app: no such file or directory
Docker compose version: 1.13.0, build 1719ceb
Docker version: 17.03.1-ce, build c6d412e
It looks like the error is my fault. Per documentation:
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.
Nonetheless I will have this issue remained open as the behavior seems inconsistent to me.
What about this behavior is inconsistent? It's a security feature that prevents the Dockerfile to escape its build context and potentially damage your machine, or access sensitive data.
Ah yes I totally get that. I should have clarified what I meant by "inconsistent behavior", and by that I mean the absolute -> relative path behavior. I surmise that this is simply an implementation detail. Though it would be better if the error is more on point when users are using paths outside the build context.
I have the similar problem
Version 3
creditcard-monk:
build:
context: ./creditcard
dockerfile: Dockerfile
args:
JAR_FILE: target/creditcard-1.0.0.jar
My requirement is that the jar is present in target directory of creditcard (mentioned in context)
My docker file copies this jar file to the container lib directory .and its failing as the builds are done under docker-lib temp directories.
failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder347176151/target/creditcard-1.0.0.jar: no such file or directory
Please help
Most helpful comment
I have the similar problem
Version 3
creditcard-monk: build: context: ./creditcard dockerfile: Dockerfile args: JAR_FILE: target/creditcard-1.0.0.jarMy requirement is that the jar is present in target directory of creditcard (mentioned in context)
My docker file copies this jar file to the container lib directory .and its failing as the builds are done under docker-lib temp directories.
failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder347176151/target/creditcard-1.0.0.jar: no such file or directoryPlease help