How to write commands with multiple lines in Dockerfile while preserving the new lines?
I want to write the following RUN command in the Dockerfile. But, docker is not preserving the new lines.
RUN echo "[repo]
name = YUM Repository
baseurl = https://example.com/packages/
enabled = 1
gpgcheck = 0" > /etc/yum.repos.d/Repo.repoxyz
I know that at the end of each line escapes the new line. But, is there any way that I can write multiple lines preserving the new line?
docker dockerfile
add a comment |
I want to write the following RUN command in the Dockerfile. But, docker is not preserving the new lines.
RUN echo "[repo]
name = YUM Repository
baseurl = https://example.com/packages/
enabled = 1
gpgcheck = 0" > /etc/yum.repos.d/Repo.repoxyz
I know that at the end of each line escapes the new line. But, is there any way that I can write multiple lines preserving the new line?
docker dockerfile
Are you using non *nix platform? Because this works fine for me on Linux.
– user
Feb 19 '16 at 20:50
@user, I was using Linux.
– Venkata Jaswanth
Jan 9 '17 at 17:15
add a comment |
I want to write the following RUN command in the Dockerfile. But, docker is not preserving the new lines.
RUN echo "[repo]
name = YUM Repository
baseurl = https://example.com/packages/
enabled = 1
gpgcheck = 0" > /etc/yum.repos.d/Repo.repoxyz
I know that at the end of each line escapes the new line. But, is there any way that I can write multiple lines preserving the new line?
docker dockerfile
I want to write the following RUN command in the Dockerfile. But, docker is not preserving the new lines.
RUN echo "[repo]
name = YUM Repository
baseurl = https://example.com/packages/
enabled = 1
gpgcheck = 0" > /etc/yum.repos.d/Repo.repoxyz
I know that at the end of each line escapes the new line. But, is there any way that I can write multiple lines preserving the new line?
docker dockerfile
docker dockerfile
edited Jun 27 '18 at 19:38
Benjamin W.
20.6k134856
20.6k134856
asked Oct 30 '15 at 15:13
Venkata JaswanthVenkata Jaswanth
186129
186129
Are you using non *nix platform? Because this works fine for me on Linux.
– user
Feb 19 '16 at 20:50
@user, I was using Linux.
– Venkata Jaswanth
Jan 9 '17 at 17:15
add a comment |
Are you using non *nix platform? Because this works fine for me on Linux.
– user
Feb 19 '16 at 20:50
@user, I was using Linux.
– Venkata Jaswanth
Jan 9 '17 at 17:15
Are you using non *nix platform? Because this works fine for me on Linux.
– user
Feb 19 '16 at 20:50
Are you using non *nix platform? Because this works fine for me on Linux.
– user
Feb 19 '16 at 20:50
@user, I was using Linux.
– Venkata Jaswanth
Jan 9 '17 at 17:15
@user, I was using Linux.
– Venkata Jaswanth
Jan 9 '17 at 17:15
add a comment |
3 Answers
3
active
oldest
votes
Start your command with $'
, end it with '
and use n
for newlines, like this:
RUN echo $'[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0' > /etc/yum.repos.d/Repo.repoxyz
1
It is working! Thank you!
– Venkata Jaswanth
Oct 30 '15 at 15:45
Is the $ syntax after echo a feature of Dockerfile? Because, I couldn't find about it in the documentation.
– Venkata Jaswanth
Nov 2 '15 at 17:29
4
It is bash syntax. See this question for more info: stackoverflow.com/a/11966402/1395437
– Daniel Zolnai
Nov 2 '15 at 18:25
7
Please, explain what you're doing, don't just drop an opaque solution
– Édouard Lopez
Sep 22 '16 at 9:34
3
A word of caution: the$' ... n
technique depends on the shell that dockerRUN
uses beingbash
. On some systems (such as Ubuntu) the shell RUN uses is/bin/sh
which is often a link todash
which is NOTbash
and does not understand the$'
syntax.
– Anon
Aug 4 '18 at 7:30
|
show 2 more comments
I used printf
. Writing all the text in one line using "n".
Executing:
RUN printf 'example ntext nhere' >> example.txt
inserts:
example
text
here
in example.txt
Actually a clever and cleaner solution IMO. Thank you.
– David Tabernero M.
Dec 4 '18 at 18:33
add a comment |
You can use:
RUN echo "
[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0
" > /etc/yum.repos.d/Repo.repoxyz
This way you will have a quick way to check what the file contents are. You just need to be aware that you need to end every line with and insert the
n
when needed.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33439230%2fhow-to-write-commands-with-multiple-lines-in-dockerfile-while-preserving-the-new%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Start your command with $'
, end it with '
and use n
for newlines, like this:
RUN echo $'[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0' > /etc/yum.repos.d/Repo.repoxyz
1
It is working! Thank you!
– Venkata Jaswanth
Oct 30 '15 at 15:45
Is the $ syntax after echo a feature of Dockerfile? Because, I couldn't find about it in the documentation.
– Venkata Jaswanth
Nov 2 '15 at 17:29
4
It is bash syntax. See this question for more info: stackoverflow.com/a/11966402/1395437
– Daniel Zolnai
Nov 2 '15 at 18:25
7
Please, explain what you're doing, don't just drop an opaque solution
– Édouard Lopez
Sep 22 '16 at 9:34
3
A word of caution: the$' ... n
technique depends on the shell that dockerRUN
uses beingbash
. On some systems (such as Ubuntu) the shell RUN uses is/bin/sh
which is often a link todash
which is NOTbash
and does not understand the$'
syntax.
– Anon
Aug 4 '18 at 7:30
|
show 2 more comments
Start your command with $'
, end it with '
and use n
for newlines, like this:
RUN echo $'[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0' > /etc/yum.repos.d/Repo.repoxyz
1
It is working! Thank you!
– Venkata Jaswanth
Oct 30 '15 at 15:45
Is the $ syntax after echo a feature of Dockerfile? Because, I couldn't find about it in the documentation.
– Venkata Jaswanth
Nov 2 '15 at 17:29
4
It is bash syntax. See this question for more info: stackoverflow.com/a/11966402/1395437
– Daniel Zolnai
Nov 2 '15 at 18:25
7
Please, explain what you're doing, don't just drop an opaque solution
– Édouard Lopez
Sep 22 '16 at 9:34
3
A word of caution: the$' ... n
technique depends on the shell that dockerRUN
uses beingbash
. On some systems (such as Ubuntu) the shell RUN uses is/bin/sh
which is often a link todash
which is NOTbash
and does not understand the$'
syntax.
– Anon
Aug 4 '18 at 7:30
|
show 2 more comments
Start your command with $'
, end it with '
and use n
for newlines, like this:
RUN echo $'[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0' > /etc/yum.repos.d/Repo.repoxyz
Start your command with $'
, end it with '
and use n
for newlines, like this:
RUN echo $'[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0' > /etc/yum.repos.d/Repo.repoxyz
edited Mar 24 '17 at 16:26
answered Oct 30 '15 at 15:33
Daniel ZolnaiDaniel Zolnai
9,64034059
9,64034059
1
It is working! Thank you!
– Venkata Jaswanth
Oct 30 '15 at 15:45
Is the $ syntax after echo a feature of Dockerfile? Because, I couldn't find about it in the documentation.
– Venkata Jaswanth
Nov 2 '15 at 17:29
4
It is bash syntax. See this question for more info: stackoverflow.com/a/11966402/1395437
– Daniel Zolnai
Nov 2 '15 at 18:25
7
Please, explain what you're doing, don't just drop an opaque solution
– Édouard Lopez
Sep 22 '16 at 9:34
3
A word of caution: the$' ... n
technique depends on the shell that dockerRUN
uses beingbash
. On some systems (such as Ubuntu) the shell RUN uses is/bin/sh
which is often a link todash
which is NOTbash
and does not understand the$'
syntax.
– Anon
Aug 4 '18 at 7:30
|
show 2 more comments
1
It is working! Thank you!
– Venkata Jaswanth
Oct 30 '15 at 15:45
Is the $ syntax after echo a feature of Dockerfile? Because, I couldn't find about it in the documentation.
– Venkata Jaswanth
Nov 2 '15 at 17:29
4
It is bash syntax. See this question for more info: stackoverflow.com/a/11966402/1395437
– Daniel Zolnai
Nov 2 '15 at 18:25
7
Please, explain what you're doing, don't just drop an opaque solution
– Édouard Lopez
Sep 22 '16 at 9:34
3
A word of caution: the$' ... n
technique depends on the shell that dockerRUN
uses beingbash
. On some systems (such as Ubuntu) the shell RUN uses is/bin/sh
which is often a link todash
which is NOTbash
and does not understand the$'
syntax.
– Anon
Aug 4 '18 at 7:30
1
1
It is working! Thank you!
– Venkata Jaswanth
Oct 30 '15 at 15:45
It is working! Thank you!
– Venkata Jaswanth
Oct 30 '15 at 15:45
Is the $ syntax after echo a feature of Dockerfile? Because, I couldn't find about it in the documentation.
– Venkata Jaswanth
Nov 2 '15 at 17:29
Is the $ syntax after echo a feature of Dockerfile? Because, I couldn't find about it in the documentation.
– Venkata Jaswanth
Nov 2 '15 at 17:29
4
4
It is bash syntax. See this question for more info: stackoverflow.com/a/11966402/1395437
– Daniel Zolnai
Nov 2 '15 at 18:25
It is bash syntax. See this question for more info: stackoverflow.com/a/11966402/1395437
– Daniel Zolnai
Nov 2 '15 at 18:25
7
7
Please, explain what you're doing, don't just drop an opaque solution
– Édouard Lopez
Sep 22 '16 at 9:34
Please, explain what you're doing, don't just drop an opaque solution
– Édouard Lopez
Sep 22 '16 at 9:34
3
3
A word of caution: the
$' ... n
technique depends on the shell that docker RUN
uses being bash
. On some systems (such as Ubuntu) the shell RUN uses is /bin/sh
which is often a link to dash
which is NOT bash
and does not understand the $'
syntax.– Anon
Aug 4 '18 at 7:30
A word of caution: the
$' ... n
technique depends on the shell that docker RUN
uses being bash
. On some systems (such as Ubuntu) the shell RUN uses is /bin/sh
which is often a link to dash
which is NOT bash
and does not understand the $'
syntax.– Anon
Aug 4 '18 at 7:30
|
show 2 more comments
I used printf
. Writing all the text in one line using "n".
Executing:
RUN printf 'example ntext nhere' >> example.txt
inserts:
example
text
here
in example.txt
Actually a clever and cleaner solution IMO. Thank you.
– David Tabernero M.
Dec 4 '18 at 18:33
add a comment |
I used printf
. Writing all the text in one line using "n".
Executing:
RUN printf 'example ntext nhere' >> example.txt
inserts:
example
text
here
in example.txt
Actually a clever and cleaner solution IMO. Thank you.
– David Tabernero M.
Dec 4 '18 at 18:33
add a comment |
I used printf
. Writing all the text in one line using "n".
Executing:
RUN printf 'example ntext nhere' >> example.txt
inserts:
example
text
here
in example.txt
I used printf
. Writing all the text in one line using "n".
Executing:
RUN printf 'example ntext nhere' >> example.txt
inserts:
example
text
here
in example.txt
answered Apr 19 '16 at 14:12
CTodeaCTodea
459417
459417
Actually a clever and cleaner solution IMO. Thank you.
– David Tabernero M.
Dec 4 '18 at 18:33
add a comment |
Actually a clever and cleaner solution IMO. Thank you.
– David Tabernero M.
Dec 4 '18 at 18:33
Actually a clever and cleaner solution IMO. Thank you.
– David Tabernero M.
Dec 4 '18 at 18:33
Actually a clever and cleaner solution IMO. Thank you.
– David Tabernero M.
Dec 4 '18 at 18:33
add a comment |
You can use:
RUN echo "
[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0
" > /etc/yum.repos.d/Repo.repoxyz
This way you will have a quick way to check what the file contents are. You just need to be aware that you need to end every line with and insert the
n
when needed.
add a comment |
You can use:
RUN echo "
[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0
" > /etc/yum.repos.d/Repo.repoxyz
This way you will have a quick way to check what the file contents are. You just need to be aware that you need to end every line with and insert the
n
when needed.
add a comment |
You can use:
RUN echo "
[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0
" > /etc/yum.repos.d/Repo.repoxyz
This way you will have a quick way to check what the file contents are. You just need to be aware that you need to end every line with and insert the
n
when needed.
You can use:
RUN echo "
[repo] n
name = YUM Repository n
baseurl = https://example.com/packages/ n
enabled = 1 n
gpgcheck = 0
" > /etc/yum.repos.d/Repo.repoxyz
This way you will have a quick way to check what the file contents are. You just need to be aware that you need to end every line with and insert the
n
when needed.
answered Jan 7 at 12:43
Paulo FidalgoPaulo Fidalgo
16k66695
16k66695
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33439230%2fhow-to-write-commands-with-multiple-lines-in-dockerfile-while-preserving-the-new%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you using non *nix platform? Because this works fine for me on Linux.
– user
Feb 19 '16 at 20:50
@user, I was using Linux.
– Venkata Jaswanth
Jan 9 '17 at 17:15