Skip to content

Add support for Dockerfile CMD options#10775

Merged
icecrime merged 1 commit intomoby:masterfrom
duglin:BuilderFlags
May 4, 2015
Merged

Add support for Dockerfile CMD options#10775
icecrime merged 1 commit intomoby:masterfrom
duglin:BuilderFlags

Conversation

@duglin
Copy link
Copy Markdown
Contributor

@duglin duglin commented Feb 13, 2015

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:

  • COPY --ignore-mtime ...
  • COPY --user=john ...
  • RUN --ignore-rc ...

Signed-off-by: Doug Davis dug@us.ibm.com

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awww, no tests with JSON syntax + args? 👼

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have such a mental block against the JSON syntax :-)
Added 'em.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@jimmycuadra
Copy link
Copy Markdown
Contributor

I still think it's not clear that, at least in the case of RUN, the options are for the Dockerfile command itself and not to the shell. I think having some sort of syntax around the Dockerfile command options makes it more clear. I can see this confusing or tripping people up as is.

builder/bflag.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors like these should cause panics, because they are programming errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyphar fixed

@cyphar
Copy link
Copy Markdown
Contributor

cyphar commented Feb 18, 2015

👍:shipit:

@thaJeztah
Copy link
Copy Markdown
Member

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)

@curtiszimmerman
Copy link
Copy Markdown

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.

@duglin
Copy link
Copy Markdown
Contributor Author

duglin commented Feb 19, 2015

@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.

@thaJeztah
Copy link
Copy Markdown
Member

@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 :)

@duglin
Copy link
Copy Markdown
Contributor Author

duglin commented Feb 26, 2015

@jfrazelle ping

@duglin
Copy link
Copy Markdown
Contributor Author

duglin commented Feb 27, 2015

@jfrazelle @crosbymichael any comments on this one?

@duglin
Copy link
Copy Markdown
Contributor Author

duglin commented Mar 17, 2015

@jfrazelle @crosbymichael I'd really like to see this in 1.6 - thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this vars? I think it will be more idiomatic to use them as local in loop.

@thaJeztah
Copy link
Copy Markdown
Member

@cyphar I don't follow?

@ryneeverett
Copy link
Copy Markdown

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.

duglin pushed a commit to duglin/docker that referenced this pull request May 5, 2015
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>
duglin pushed a commit to duglin/docker that referenced this pull request May 6, 2015
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>
duglin pushed a commit to duglin/docker that referenced this pull request May 7, 2015
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>
@duglin duglin deleted the BuilderFlags branch May 9, 2015 12:52
@alexcesaro
Copy link
Copy Markdown

This PR has been merged but the documentation does not mention this new syntax and when I do COPY --user=me with Docker 1.9.1 I get: Unknown flag: user.

What is the status of this feature?

@cyphar
Copy link
Copy Markdown
Contributor

cyphar commented Dec 18, 2015

@alexcesaro This PR only implements the flag code, not --user or any other specific flag.

@alexcesaro
Copy link
Copy Markdown

Ok thanks. Is there an open issue I can follow on the subject? Or has the --user flag been rejected?

@thaJeztah
Copy link
Copy Markdown
Member

@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

@moon-musick
Copy link
Copy Markdown

@thaJeztah since Dockerfile syntax is not frozen anymore is there any chance the flags processing will be finally implemented?

@duglin
Copy link
Copy Markdown
Contributor Author

duglin commented Sep 13, 2016

@moon-musick the code is there, we just don't have any dockerfile cmds that define flags, yet.

@moon-musick
Copy link
Copy Markdown

@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 user flag for the COPY command?

@duglin
Copy link
Copy Markdown
Contributor Author

duglin commented Sep 14, 2016

@moon-musick ah, yea slightly different question :-) and I agree with you we should add that

@cyphar
Copy link
Copy Markdown
Contributor

cyphar commented Sep 14, 2016

I personally would prefer something like COPYAS or something. I still (after all this time) don't like this calling convention. But I'm burnt out on this issue and beyond caring.

@duglin
Copy link
Copy Markdown
Contributor Author

duglin commented Sep 14, 2016

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.

@Clement-TS
Copy link
Copy Markdown

Clement-TS commented Oct 20, 2016

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

@cyphar
Copy link
Copy Markdown
Contributor

cyphar commented Oct 20, 2016

@Clement-TS That idea was proposed by @thaJeztah almost 2.5 years ago in #4907.

@gautaz
Copy link
Copy Markdown

gautaz commented Oct 20, 2016

#4907 was closed by @jessfraz:

Then from there, patches/features like this can be re-thought. Hope you can understand.

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?

@cyphar
Copy link
Copy Markdown
Contributor

cyphar commented Oct 20, 2016

@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 COPY to work properly with USER).

@davidbarton
Copy link
Copy Markdown

I understand introducing versioning is long way to go. So question is if we can get those flags working anytime soon?

@g13013
Copy link
Copy Markdown

g13013 commented Jan 29, 2017

Any update on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.