Skip to content

Instantly share code, notes, and snippets.

@atheiman
Last active March 22, 2025 01:33
Show Gist options
  • Save atheiman/247a4859a6c33de8d42c50dd7a888510 to your computer and use it in GitHub Desktop.
Save atheiman/247a4859a6c33de8d42c50dd7a888510 to your computer and use it in GitHub Desktop.
Dockerfile container startup script options

These Dockerfile examples demonstrate two options for running a script at container startup, then running the main container process. The example script downloads index.html from https://example.com/ and writes it into Tomcat webapps directory. The index.html is then served by the container at http://localhost:8080/default-app/.

docker build . -t tomcat-with-startup
docker run --rm -it -p 8080:8080 tomcat-with-startup
FROM docker.io/tomcat
COPY <<EOF /bin/startup.sh
#!/bin/sh
set -x
mkdir -p "$CATALINA_HOME/webapps/default-app"
curl -Ls -o "$CATALINA_HOME/webapps/default-app/index.html" 'https://example.com/'
exec catalina.sh run
EOF
RUN chmod +x /bin/startup.sh
CMD /bin/startup.sh
FROM docker.io/tomcat
COPY <<EOF /bin/startup.sh
#!/bin/sh
set -x
mkdir -p "$CATALINA_HOME/webapps/default-app"
curl -Ls -o "$CATALINA_HOME/webapps/default-app/index.html" 'https://example.com/'
EOF
RUN chmod +x /bin/startup.sh
CMD ["/bin/sh", "-c", "/bin/startup.sh && catalina.sh run"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment