简体   繁体   中英

Syntax Error: Multiline bash command in dockerfile RUN statement

I have this Dockerfile, to which I am echoing the following line:

echo $"RUN cat file | while read pkg \
do\
  sudo apt-get install -qy $pkg \
done" >> Dockerfile

Now, when docker executes this line, I get the following error:

/bin/sh: -c: line 1: syntax error: unexpected end of file The command '/bin/sh -c cat autobuild/buildenv_packages | while read pkg do sudo apt-get install -qy done' returned a non-zero code: 1

I know there is something small and syntactical I am missing, but I am unable to figure it out. Notice that the $pkg variable in the apt-get install statement isn't in the error.

Any assistance would be appreciated!

The backslashes in your code only prevent the string from containing literal newlines; they are not written to the Dockerfile . Without a newline (or a semicolon) before do , the while condition never ends; you just have a giant list of arguments for the command read .

echo 'RUN while read pkg; do sudo apt-get install -qy "$pkg"; done < file' >> Dockerfile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM