You need to quote the EOF token:
cat <<"EOF" > Dockerfile
RUN apt-get update -y \
&& apt-get install -y \
If you want to expand variables too, you need to escape the backslashes and not use any quotes.
Here's the corresponding
man bash section.
No parameter and variable expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If any part of
word is quoted, the delimiter is the result of quote removal on word,
and the lines in the here-document are not expanded. If word is
unquoted, all lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion, the charac‐
ter sequence \<newline> is ignored, and \ must be used to quote the
characters \, $, and `.