Skip to content

Instantly share code, notes, and snippets.

@abn
Last active July 31, 2024 06:26
Show Gist options
  • Save abn/a16e9d799312fb492861 to your computer and use it in GitHub Desktop.
Save abn/a16e9d799312fb492861 to your computer and use it in GitHub Desktop.
Dockerfile alternatives for heredoc
#printf
RUN printf '#!/bin/bash\n\
echo hello world from line 1\n\
echo hello world from line 2'\
>> /tmp/hello
#echo
RUN echo -e '#!/bin/bash\n\
echo hello world from line 1\n\
echo hello world from line 2'\
>> /tmp/hello
@image72
Copy link

image72 commented Jul 31, 2024

FROM debian
RUN <<EOT bash
  set -eux
  to_install=(
    vim
  )
  apt-get update
  failing_command # set -e exit with non-zero status 
  apt-get install -y "\${to_install[@]}"
EOT

# execute list shell
RUN <<EOF
apt-get update
apt-get upgrade -y
apt-get install -y ...
EOF

# run python
RUN <<EOF
#!/usr/bin/env python3
with open("/hello", "w") as f:
    print("Hello", file=f)
    print("World", file=f)
EOF

# create index.html
COPY <<EOF /usr/share/nginx/html/index.html
<html>hello, index</html>
EOF

# create /etc/mysql/my.cnf
RUN <<-EOF > /etc/mysql/my.cnf
[mysqld]
user=root
datadir=/app/mysql
port=3306
log-bin=/app/mysql/mysql-bin
EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment