Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute path passed as argument in docker-compose to Dockerfile becomes relative in linux #4849

Closed
markgarcia opened this issue May 22, 2017 · 4 comments

Comments

@markgarcia
Copy link

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

@markgarcia
Copy link
Author

markgarcia commented May 22, 2017

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.

@markgarcia markgarcia reopened this May 22, 2017
@shin-
Copy link

shin- commented May 22, 2017

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.

@shin- shin- closed this as completed May 22, 2017
@markgarcia
Copy link
Author

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.

@fryder
Copy link

fryder commented Jan 5, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants