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

Allow Heredoc (or multi line instructions) in RUN command (in Dockerfile) #1554

Closed
brikou opened this issue Aug 15, 2013 · 44 comments
Closed

Comments

@brikou
Copy link

brikou commented Aug 15, 2013

An interesting use case would be to patch config file within dockerfile

RUN cat << EOF | patch --strip 0
--- /etc/apache2/conf.d/charset
--- /etc/apache2/conf.d/charset
@@ -3,4 +3,4 @@
 # have this encoding. It will override any encoding given in the files
 # in meta http-equiv or xml encoding tags.

-#AddDefaultCharset UTF-8
+AddDefaultCharset UTF-8
EOF
@shykes
Copy link
Contributor

shykes commented Aug 15, 2013

To focus on your specific example: it might make more sense to commit your config & dockerfile to a git or mercurial repository, and ADD the config file during the build.

  ​

   



—

@solomonstre
@getdocker

On Thu, Aug 15, 2013 at 7:59 AM, Brikou CARRE notifications@github.com
wrote:

An interesting example would be to patch config file with dockerfile

RUN cat << EOF | patch --strip 0
--- /etc/apache2/conf.d/charset
--- /etc/apache2/conf.d/charset
@@ -3,4 +3,4 @@
 # have this encoding. It will override any encoding given in the files
 # in meta http-equiv or xml encoding tags.
-#AddDefaultCharset UTF-8
+AddDefaultCharset UTF-8
EOF

Reply to this email directly or view it on GitHub:
#1554

@unclejack
Copy link
Contributor

I'm closing this in favor of #1799. If you think this issue should be re-opened, please re-open it or ask me to do it.

@d11wtq
Copy link

d11wtq commented Mar 13, 2014

The problem with using a separate file + ADD is that it will be cached, so you can't tweak what would have been in the heredoc. You have to completely avoid caching everything that comes before the multi-line part.

If you actually want to use heredoc, as is really common in the case of the pattern:

cat > /etc/some/file.conf <<'EOF'
Whatever multi-line stuff
I need to put here
without any headaches
EOF

Then using the \ syntax, Docker squashes it into a single line and breaks the heredoc.

@tianon
Copy link
Member

tianon commented Mar 13, 2014

ADD does cache though, for several versions now

@d11wtq
Copy link

d11wtq commented Mar 13, 2014

Yes, that is a problem. I want to be able to edit the file and have docker do "smart" caching. If the string that is in this file was part of a command, docker would understand it can't use the cache. But put it in a file and suddenly the cache effectively makes the file immutable, unless you completely go around the caching, which in my case (entire llvm toolchain) I don't want to do.

@tianon
Copy link
Member

tianon commented Mar 14, 2014

Previously, ADD was just always a cache bust, but now it is as you might expect, busting based on a checksum of what was added, so changing the file will cause a natural cache bust as you might expect.

@HelloGrayson
Copy link

+1 here

@gnutix
Copy link

gnutix commented Jun 23, 2014

+1 !

@iby
Copy link

iby commented Nov 15, 2014

+10000000

@ailjushkin
Copy link

How can I run something from a user different from the root user when building new image ?

@unclejack
Copy link
Contributor

@PositiveAlex You can use USER someuser after adding that user.

@ailjushkin
Copy link

@unclejack thank you, and sorry, I should read manual more accurate first...

@zzeroo
Copy link

zzeroo commented Aug 20, 2015

No Heredoc and a little ugly but it work ...

RUN echo " \n\
KERNEL=="mali", MODE="0660", GROUP="video" \n\
KERNEL=="ump", MODE="0660", GROUP="video" \n\
" >> /etc/udev/rules.d/50-mali.rules

+1 Heredoc

@GordonTheTurtle
Copy link

USER POLL

The best way to get notified when there are changes in this discussion is by clicking the Subscribe button in the top right.

The people listed below have appreciated your meaningfull discussion with a random +1:

@sleaze
@MatthewRalston
@dsissitka
@mingfang
@grigio
@devinrsmith
@afolarin
@ggershoni

@xasm83
Copy link

xasm83 commented Sep 15, 2015

+1

@ryanmaclean
Copy link

Would definitely be interested in seeing this as well! 👍

@thaJeztah
Copy link
Member

Also see this comment; #16058 (comment)

@nimkar
Copy link

nimkar commented Jan 28, 2016

+1 for Heredoc

@j4zzcat
Copy link

j4zzcat commented Feb 2, 2016

+1

4 similar comments
@eliezio
Copy link

eliezio commented Mar 3, 2016

+1

@sergeyklay
Copy link

+1

@geekaholic
Copy link

+1

@cjac
Copy link

cjac commented Mar 12, 2016

+1

@C-Duv
Copy link

C-Duv commented Mar 12, 2016

Stop posting +1, use the new GitHub reactions feature.

@sleaze
Copy link

sleaze commented Mar 14, 2016

+1 Thank you! So glad and happy this got implemented!

@djmaze
Copy link
Contributor

djmaze commented Mar 14, 2016

@cjac You referenced an old PR which implemented the \ multiline syntax. The Heredoc syntax has not been implemented yet. (And that's what this issue is now about.) It seems the Dockerfile syntax is currently frozen, so this probably won't be possible before Docker 2.0 (or something like that..).

@sleaze
Copy link

sleaze commented Mar 15, 2016

Oh :/ sad now

@junjiemars
Copy link

Heredoc is awesome for writing small script/config, etc. I don't care what's cache it or not.

@denysvitali
Copy link

👍 This should be implemented!

@mingfang
Copy link

+1 just to piss off @GordonTheTurtle

@verbunk
Copy link

verbunk commented Apr 11, 2017

This thread is a bit dated now but I still haven't found native support for this. Anyhoo, in case it helps someone else what I do is pull alpine, add in coreutils as a virtual-dep, move base64 to /usr/local/bin and in my Dockerfile, RUN echo "" | base64 --decode > /etc/myconf.conf so it will copy over my base configs. Supports line breaks in the encoded form so no mess (if you consider this non-messy). Extra points if you use envsubst (add as virtual-dep like above, then move before deleting the large unnecessary packages) to mod the config file with your ENV variables.

I just really hate extra files hanging around.

@VelorumS
Copy link

VelorumS commented Apr 28, 2017

One possible workaround is the following:

bash -c "$(/bin/echo -e "cat > /etc/my.config <<EOM\
\n########################################################\
\n# The file\
\n########################################################\
\na = b\
\nEOM\n")

Prefix everything with \n and suffix with \. The echo evaluates newlines for bash.

@sleaze
Copy link

sleaze commented Jan 24, 2018

+1

BUMP still waiting on this one ......

Cheerio

@thaJeztah
Copy link
Member

@sleaze see #34423

@ktf

This comment has been minimized.

2 similar comments
@sharkguto

This comment has been minimized.

@mkomadel

This comment has been minimized.

@brikou
Copy link
Author

brikou commented Oct 4, 2018

@unclejack 5 years ago you told me you can reopen? Can you?

@thaJeztah
Copy link
Member

There is a new issue / proposal that I linked to; #34423. Please continue the conversation over there (also, please don't add +1's - it generates a lot of noise, and distracts from the actual discussion)

@brikou
Copy link
Author

brikou commented Oct 4, 2018

@thaJeztah your proposal is nice but really not the same as not dealing with shell heredoc.

@thaJeztah
Copy link
Member

@brikou I think it should allow you to do that, e.g. something like this;

RUN <<EOF
cat > /etc/my.config <<EOM
########################################################
# The file
########################################################
a = b
EOM
EOF

@SolomonShorser-OICR

This comment has been minimized.

1 similar comment
@RobvH

This comment has been minimized.

@thaJeztah
Copy link
Member

Locking the conversation on this issue in favor of #34423. Please continue the conversation over there (also, please don't add +1's - it generates a lot of noise, and distracts from the actual discussion)

@moby moby locked and limited conversation to collaborators Feb 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests