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

Variable expansion in RUN --mount command does not work #2909

Closed
dln22 opened this issue Jun 15, 2022 · 5 comments
Closed

Variable expansion in RUN --mount command does not work #2909

dln22 opened this issue Jun 15, 2022 · 5 comments

Comments

@dln22
Copy link

dln22 commented Jun 15, 2022

I am trying to mount a source dir for one of my run commands in the docker file. Ideally, I would like to pass source dir as build-arg when calling docker build. However, I have noticed that the passed source dir is not correctly expanded. Here is a minimum dockerfile example reproducing the problem:

FROM alpine:latest
ARG source_dir
RUN --mount=type=bind,target=/indomain,source=${source_dir} 

and then I call it as follows:

docker buildx build -f Dockerfile --build-arg source_dir=./data .

and this is the error I get:

 => ERROR [2/2] RUN --mount=type=bind,target=/indomain,source=./data                                                                                                                         0.0s
------
 > [2/2] RUN --mount=type=bind,target=/indomain,source=./data:
------
error: failed to solve: failed to compute cache key: "/${source_dir}" not found: not found

It is a bit confusing as the first ERROR line shows the variable expanded, but then at the bottom, it shows it as not expanded.

According to the #2089 merge request, the variable expansion should be now supported?

@tonistiigi
Copy link
Member

What version of dockerfile are you using? This was added in 1.3 https://github.com/moby/buildkit/releases/tag/dockerfile%2F1.3.0

@dln22
Copy link
Author

dln22 commented Jun 15, 2022

This is the docker version output:

>docker version
Client:
 Cloud integration: v1.0.22
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:44:07 2021
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:43:56 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

@dln22
Copy link
Author

dln22 commented Jun 15, 2022

Hmm I am not too familiar with different dockerfile versions. I have tried to add the # syntax line to my dockerfile:

# syntax=docker.io/docker/dockerfile:1.3.0
FROM alpine:latest
ARG source_dir
RUN --mount=type=bind,target=/indomain,source=${source_dir} 

but that resulted in another error:

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2B 0.2s done
#1 DONE 0.3s
error: failed to solve: failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount852294124/Dockerfile: no such file or directory

@dln22
Copy link
Author

dln22 commented Jun 15, 2022

ok, I got it working! Issue can be closed. Thanks for help @tonistiigi

@sfariaNG
Copy link

For future reference if anyone else runs into this issue, add the following as the very first line in the Dockerfile, before anything else including comments:
# syntax=docker.io/docker/dockerfile:1.3.0

Tested on:

 Plugins:
   buildx: Docker Buildx (Docker Inc., v0.9.1)
...
 Server Version: 20.10.21

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