pypep278 pypep278 - 4 months ago 30
Linux Question

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 \
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
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