-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
ARG before FROM in Dockerfile doesn't behave as expected #34129
Comments
@thaJeztah correct me if I'm wrong. @Benjamin-Dobell after investigating this, 239c53b is not the origin of this behavior. Basically, after the From what I found the purpose of |
Yes, this doesn't look like a bug; see this pull request, which adds some more information docker/cli#333 |
@thaJeztah I guess we can close this |
Irrespective of whether this was implemented this way intentionally or it's a bug; I think it's a bit of a usability nightmare. It's not clearly documented that this is the expected behaviour, and it makes for messy What if I intend to use an What happens if I use default value syntax |
The same as it would be if you're not using multi-stage build; empty / no value set |
@thaJeztah I know that's true now, I've experimented with it. The issue is that it's hugely non-obvious. If this is expected behaviour and no-one is willing to change it. Then at the very least |
/cc @tonistiigi @dnephin |
Improved documentation is always appreciated, and would have saved me some time. However, just because behaviour is documented doesn't preclude the behaviour itself from scrutiny.
|
I should note, that I'm not actually an advocate of expanding the grammar when the usage of the existing grammar can be expanded. However, in this particular instance It's extremely confusing in single stage builds, and perhaps more-so in multi-stage ones. If arguments really are tied to build stages (although I must confess I'm not sure why this is desirable), then you've suddenly a need to look at the previous "stage", beyond the Realistically, you can't pass different arguments to different build stages (they're typically provided as CLI arguments). So there's no legitimate reason to scope arguments to build stages. Additionally:
So there is zero incentive to intersperse |
The new
It's the opposite. Build args are defined by stage so you only need to look at the args for the current stage. Whatever you define in other stages has no effect on the current stage.
All args are used in every |
The semantics changed with multi-stage builds. The change doesn't really have anything to do with
I think you're misunderstanding the scope. They are only scoped to the stage where they are declared.
The use cases supported by a Dockerfile expanded quite a bit with multi-stage builds. It's no longer the case that a single Dockerfile will produce a single image. You can use In this context the design should make more sense. Although the values might not change, which lines actually run will change depending on the |
Yikes! That also needs documenting... and changing.
When looking at a
|
I'm was just clarifying what "first use" means. You use an
|
To be clear, I'm not saying I don't understand how the current implementation works, what has been written in this issue explains it clearly enough. I'm suggesting the implementation itself is non-ideal and confusing; after all, I read the existing docs and literally cloned Docker compose, Docker client and finally Docker before working out what was going on - at which point I opened this issue. It's just too complicated. Adding so much complexity to the
I don't think this is necessarily 100% accurate that multi-stage and The properties of
( A feature request comes along:
Reasonable enough, the two previously defined properties still hold if implemented. We now have a third property:
This can cleanly be implemented, without any backwards compatibility issues. Except, it wasn't; it could have been, but it wasn't. Instead, property That's changing the semantics of Mind you, this constraint is artificial in nature, there's zero reason Anyway, my issue is complexity; that's subjective and given I'm not a maintainer, not for me to decide. Documentation is certainly better than nothing, so this issue may be closed if you see fit. |
As a new user of I would suggest a warning that |
@Benjamin-Dobell I wanted to use build-args in multistage builds to pass secure keys to intermediate build stages which would then disappear. I haven't completely got confirmation that this is secure, but I was actually happy to see your issue. For the record, aside from implementation details which respondents seem to be burdening you with, clearing build args -- at least so they can't be read from the build history -- seems IMO to be a very important feature... well worth the complexity. UPDATE -- sigh ... I guess I spoke prematurely. Multistage builds don't help with the fact that args are written to build history. |
@shaunc Are you saying that build-arg defined for an intermediate stage is visible in the history of the final stage? This should not happen if you use |
I ran into the same issue and in order to underline the impact of that behaviour, I want so share my example here, whos cause took a significant amount of time to figure out. Still it's totally unexpected and I wont exactlly call that user experience. docker image build \
--build-arg NODE_VERSION="4.8.3" \
--build-arg NPM_VERSION="4.5.0" Works not as expected. ARG NODE_VERSION="latest"
ARG NPM_VERSION="latest"
FROM node:${NODE_VERSION}-alpine
RUN npm install -g npm@${NPM_VERSION}
... Works as intended. ARG NODE_VERSION="latest"
FROM node:${NODE_VERSION}-alpine
ARG NPM_VERSION="latest"
RUN npm install -g npm@${NPM_VERSION}
... |
https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact If this is a common pattern a PR would probably be accepted that detects this case (at least for variable substitution) and shows a warning about possible misuse. |
As far as this keyword behaves with multiple FROM statements, in "multi-stage" builds, ARG lets you specify different defaults for different stages, but there is no way (nor should there be) to pass different values explicitly to different stages. That's far more convoluted than having ARGs go into effect from the keyword down, across any number of stages/FROMs. |
If you want to use the same
|
This is an over simplification. You are not considering default values and the programming rule of
We now have the arg's default value defined twice in one file - we have lost the single source of truth. |
The example given actually takes care of default values;
I also posted some examples in #37622 (comment), #37345 (comment) |
I lost couple of hours to this. Intuitively I was expecting that ARG before FROM in multistage build will be a global ARG (for all stages). In simply gets cleared instead. |
This is horrible to way with something that seems to be a global value. |
I have a reverse twist on this. I remembered from the docs that ARG had to appear before FROM in order to be used in FROM, so I put an ARG before the FROM of my second builder declaration. And got an invalid-format error on the FROM line, because that ARG appeared after the first FROM in the file, and so was ignored when processing the second FROM line. So ARG-before-the-first-FROM is global for all FROM lines and not used in any other lines, while ARG-after-FROM is used only between that FROM and the next FROM. It is consistent in a way, but completely non-intuitive, so really the ARG-before-FROM ought to be named FROMARG as suggested earlier in this thread, because otherwise it just breaks expectations left and right. |
The ARG Dockerfile keyword has a long history of not behaving as expected. See this thread for more detail: moby/moby#34129
Docker version 19.03.6, build 369ce74a3c
results in:
Why isn't this global? What is the fix? It seems to me from reading this and other threads that a global arg is the desired and expected... |
See moby/moby#34129 So many hours wasted... :(
Sorry to bother you! @darrahts @Tob1as @bitdancer @AntonioCS @varnav @thaJeztah @himslm01 @ClementWalter @nik-shornikov @tonistiigi @Benjamin-Dobell @boaz0 @ferrouswheel @lucendio @shaunc @darrahts @ We are a software engineering team from the Jilin University of China, and we are currently carrying out research oriented to issue discussions in GitHub. In GitHub issue system, GitHub developers can leave comments to others for discussing and solving specific technology problems, which can strengthen the development of projects and cooperation among developers. However, compared with other traditional social platforms, the discussion structure of GitHub Issue is linear, and the comments are sorted in timelines. Besides, many important contents of GitHub issue discussions are flooded by the new and crowding incoming comments, making it difficult for new-comer developers search demanded information. The current discussion status reveals it is difficult for GitHub developers to quickly grasp the main content of the discussion, search for useful information, and locate responders. Thus, to overcome those challenges, we aim at proposing an automatically approach to re-build the dialogue structure of GitHub discussions and extract the key information under different discussion topics, as shown in the following Figure . The root node represents the developer who proposed the issue, and each node represents the comment with its number and the commenter. Meanwhile, the edge reflects the reply relationship, that is, each children responds to its parent node. The key information of each subtree is displayed in the lower corner of the Figure. At your convenience, could you please browse the Figure and take 5 minutes to answer 3 questions? 1: Do you think this tree-structure dialogue structure can well reflect the reply relationship of GitHub issues, and it will facilitate your understanding of the overall issue content? 2: As for your comments, do you think our approach find the correct user who you want to reply? 3: Can you tell us the key information we extracted from sub-trees can reflect the important topics of each sub-tree or not? Greatly appreciate any assistance you can provide and we are looking forward to your reply! (We guarantee that your responses will not be changed. The survey data is only utilized for this GitHub recommendation research and not for other purposes. Please feel free to fill it out.) Have a nice day! |
It would take too long to figure out what those bubbles are referring to, so if you are asking if this by itself would help me understand the issue, the answer is no. If you want real feedback I suspect you'll need something that actually displays the content. What I'd really like in long github issues is a way to see the "current status" at a glance: which PR closed the issue, which PRs are related to the issue if it is open, what the last message is from the development team regarding the issue. Another side observation: you have a lists of keywords associated with the subtree, but posters will often @ mention the github name of the person to whom they are replying. Have you considered using that as part of your algorithm? |
Thank you very much for your reply! We will carefully consider your suggestion and try our best to improve our algorithm.
…------------------ 原始邮件 ------------------
发件人: "moby/moby" ***@***.***>;
发送时间: 2022年6月13日(星期一) 晚上8:46
***@***.***>;
***@***.******@***.***>;
主题: Re: [moby/moby] ARG before FROM in Dockerfile doesn't behave as expected (#34129)
It would take too long to figure out what those bubbles are referring to, so if you are asking if this by itself would help me understand the issue, the answer is no. If you want real feedback I suspect you'll need something that actually displays the content.
What I'd really like in long github issues is a way to see the "current status" at a glance: which PR closed the issue, which PRs are related to the issue if it is open, what the last message is from the development team regarding the issue.
Another side observation: you have a lists of keywords associated with the subtree, but posters will often @ mention the github name of the person to whom they are replying. Have you considered using that as part of your algorithm?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Description
It's documented that
ARG
can appear beforeFROM
, so that arguments may be substituted into image names etc.Rather than having some
ARG
before and someARG
afterFROM
, for consistency I attempted to place all myARG
beforeFROM
. However, to my surprise (after a lot of debugging) I determined that my arguments are always blank afterFROM
.I believe the meta-arg functionality/refactoring may somehow be responsible:
239c53b
Steps to reproduce the issue:
environment
ARG (stored in /value_of_environment):Describe the results you received:
development
Describe the results you expected:
production
Additional information you deem important (e.g. issue happens only occasionally):
Altering the
Dockerfile
such thatARG
comes afterFROM
i.e.then running again:
gives the expected output of
production
.Output of
docker version
:Output of
docker info
:The text was updated successfully, but these errors were encountered: