Created
July 31, 2024 06:27
-
-
Save image72/dede55ade2400a48fccb49623ecc78ec to your computer and use it in GitHub Desktop.
heredoc in dockerfile snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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