Add support for Dockerfile CMD options#10775
Conversation
There was a problem hiding this comment.
Awww, no tests with JSON syntax + args? 👼
There was a problem hiding this comment.
I have such a mental block against the JSON syntax :-)
Added 'em.
There was a problem hiding this comment.
Perhaps edging on OCD, but you're a bit inconsistent in "where" you position the comments; here, you place if after the curly-bracket, but on line 150, you position it after the "continue". (Nitpicking for sure).
|
I still think it's not clear that, at least in the case of |
builder/bflag.go
Outdated
There was a problem hiding this comment.
Errors like these should cause panics, because they are programming errors.
|
👍 |
|
Thanks a lot for starting on this implementation, @duglin! Does this PR allow options to be spread over multiple lines? I wrote some mock-up examples on the original issue; #9934 (comment) will all those work with this? (Asking, because there was a lot of discussion in readability, most of them could probably be fixed by formatting the options in the Dockerfile) |
|
I've rolled this around in my head for a while. @thaJeztah and previous people have noted that formatting the options and the actual commands to run (with their options) onto multiple lines could really solve the problem with readability. It tends to already be accepted style in Dockerfiles to spread complex commands out across multiple lines, and I suppose this is probably going to be the case with Dockerfile command options. In lieu of a delimiter that isn't already reserved for other uses (such as shell constructs), and noting multiline command formatting and the JSON-style "pseudo-delimiter", I defer to the style in this PR. |
|
@thaJeztah yes. Normal line continuation processing (ie. 's) are processed before the CMD option parsing is done so all of that good stuff still should work as expected. |
|
@duglin great! Wasn't 100% sure (the test cases in the PR didn't use them) I think what's needed after this is a definition of options that needs to be worked on (and docs of course), but first get full approval on the format :) |
|
@jfrazelle ping |
|
@jfrazelle @crosbymichael any comments on this one? |
|
@jfrazelle @crosbymichael I'd really like to see this in 1.6 - thoughts? |
There was a problem hiding this comment.
Why we need this vars? I think it will be more idiomatic to use them as local in loop.
|
@cyphar I don't follow? |
|
I hope the backlash isn't surprising after making the decision in the comments of a narrow issue with no obvious relevance to fine-tuning Dockerfile syntax. |
Note that as of now this is just a syntax feature. Meaning it just pulls in the included Dockerfile and continues parsing. If the target Dockerfile has a FROM then it is processed and new image will be created. Once moby#10775 is merged, I'd like to add a flag like: INCLUDE --no-from ... which will tell it to skip the FROM so that the modifications will be done within the same/current image. Also, note that you can do: INLCUDE myfile.${foo} Closes: moby#735 Signed-off-by: Doug Davis <dug@us.ibm.com>
Note that as of now this is just a syntax feature. Meaning it just pulls in the included Dockerfile and continues parsing. If the target Dockerfile has a FROM then it is processed and new image will be created. Once moby#10775 is merged, I'd like to add a flag like: INCLUDE --no-from ... which will tell it to skip the FROM so that the modifications will be done within the same/current image. Also, note that you can do: INLCUDE myfile.${foo} Closes: moby#735 Signed-off-by: Doug Davis <dug@us.ibm.com>
Note that as of now this is just a syntax feature. Meaning it just pulls in the included Dockerfile and continues parsing. If the target Dockerfile has a FROM then it is processed and new image will be created. Once moby#10775 is merged, I'd like to add a flag like: INCLUDE --no-from ... which will tell it to skip the FROM so that the modifications will be done within the same/current image. Also, note that you can do: INLCUDE myfile.${foo} Closes: moby#735 Signed-off-by: Doug Davis <dug@us.ibm.com>
|
This PR has been merged but the documentation does not mention this new syntax and when I do What is the status of this feature? |
|
@alexcesaro This PR only implements the flag code, not |
|
Ok thanks. Is there an open issue I can follow on the subject? Or has the --user flag been rejected? |
|
@alexcesaro the PR (#13600) is currently closed because the Dockerfile syntax is currently frozen, due to breaking out the builder (and moving it client-side); https://github.com/docker/docker/blob/master/ROADMAP.md#22-dockerfile-syntax |
|
@thaJeztah since Dockerfile syntax is not frozen anymore is there any chance the flags processing will be finally implemented? |
|
@moon-musick the code is there, we just don't have any dockerfile cmds that define flags, yet. |
|
@duglin my question was very poorly worded, it seems. What I mean is: now the Dockerfile syntax is not frozen anymore, are there any plans to use the flags processing code to implement flags on actual Dockerfile commands, e.g. a much requested |
|
@moon-musick ah, yea slightly different question :-) and I agree with you we should add that |
|
I personally would prefer something like |
|
yea, but having ADD, COPY, COPYAS, etc... is just silly when they're all (almost) the same thing. This what what flags/options are for. |
|
May be should you guys define some kinda "version" of the Dockerfile (like it's done in docker-compose.yml files). If your concern is about the future of the Dockerfile syntax, its almost sure you will need to break the Dockerfile API /Syntax at some point. My idea could be summed up like this: DOCKERFILE "2"
FROM image
RUN adduser app && install -o app /app
USER app
# expect all /app sources to be owned by the "app" user
# no need of extra `CMD chown -R app /app` which could double the image size
ADD . /app |
|
@Clement-TS That idea was proposed by @thaJeztah almost 2.5 years ago in #4907. |
|
#4907 was closed by @jessfraz:
As already stated by @moon-musick, this item is now removed from the road map and thus the issue related to Dockerfile version seems again a valid issue to discuss about. @cyphar Can you clarify? Does it mean that #4907 has to be opened again or that another issue is to be created or referenced here if it already exists? |
|
@gautaz I mentioned it because if you wanted to open a proposal for it, it'd be useful to know that it had been suggested (and closed) before. I would recommend opening a new issue rather than reviving a dead once (since there wasn't any useful discussion in it). FWIW, I agree with the versioning problem (and tried several times and ultimately burnt out trying to get |
|
I understand introducing versioning is long way to go. So question is if we can get those flags working anytime soon? |
|
Any update on this ? |
Per the thread and @shykes approval at #9934 (comment) , this adds support for Dockerfile commands to have options - e.g:
COPY --user=john foo /tmp/
COPY --ignore-mtime foo /tmp/
Supports both booleans and strings. All options MUST come right after the Dockerfile command and MUST start with "--". Anything not starting with "--" is considered to be a normal arg for the command. "--" can be used to denote the end of these BuilderFlags - to allow for a normal arg to start with "--" if needed.
This doesn't define any options yet for any commands, but rather defines the infrastructure to do so. I added unit testcases for the parser and the new BuilderFlags structure. Once merged, we can then discuss which options we want to add. Some up for consideration:
Signed-off-by: Doug Davis dug@us.ibm.com