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

Add support for heredocs in CMD dockerfile commands #2265

Closed
wants to merge 1 commit into from

Conversation

jedevc
Copy link
Member

@jedevc jedevc commented Jul 19, 2021

As stated, this patch introduces allowing heredocs in the CMD command exactly as in the RUN command 🎉

I don't think this is particularly complex - although I do have one bit I'm not quite sure about. For the case of supporting shebangs, we can't have run-mounts for the CMD, so I've gone ahead and introduced a new copying layer in these cases (into /mnt though, since /dev isn't preserved when running). I'm happy to switch to one of the following though if that doesn't work:

  • Copy the file over in a separate layer as the CMD
  • Copy the file over in the same layer as the CMD
  • Don't support heredoc shebangs at all in CMD

@thaJeztah
Copy link
Member

Perhaps for this one we should also consider to waiting until we get more use-cases. I can see the benefit of being consistent with RUN, but on the other hand, usually CMD / ENTRYPOINT are short commands (and not as problematic as RUN instructions.

If this can be added in future without breaking backward-compatibility, I think it's ok to wait until we have practical use-cases.

@tonistiigi
Copy link
Member

Closing for now to keep the heredoc scope from growing too fast. We can revisit if there are more use-cases.

@tonistiigi tonistiigi closed this Aug 17, 2021
@thaJeztah
Copy link
Member

Thanks @jedevc !

@jedevc jedevc reopened this Sep 5, 2022
@jedevc jedevc force-pushed the dockerfile-heredocs-cmd branch 2 times, most recently from 9a36ab6 to 84f25a5 Compare September 5, 2022 11:51
This patch introduces support for using heredocs for the CMD instruction -
they work identically to the heredocs for RUN, with a couple of
differences for shebang scripts:

- We create a new layer writing the script contents to /mnt/pipes/

  Usually CMD does not create a new layer, however, the file is required
  to run the script as we would with RUN, since we want to avoid manual
  parsing of the shebang line.

- We have to use /mnt/pipes instead of /dev/pipes, since /dev/pipes is
  mounted at runtime.

Signed-off-by: Justin Chadwell <[email protected]>
@thaJeztah
Copy link
Member

I see @tonistiigi left some comments on the other PR; #3082 (comment)

I'm personally also still on the fence if we should do this; it still feels like a corner-case, and can already be (largely) resolved by using COPY with heredoc (e.g.), which I think is less confusing, and also doesn't "promote" running huge commands as part of the container startup (for which likely a regular entry point script would be more suitable)

Should we close this one again?

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.

5 participants