Skip to content

Instantly share code, notes, and snippets.

@atheiman
Last active November 10, 2025 15:46
Show Gist options
  • Select an option

  • Save atheiman/247a4859a6c33de8d42c50dd7a888510 to your computer and use it in GitHub Desktop.

Select an option

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

exec is the preferred option because the startup.sh shell script will be replaced by catalina.sh as the main container process. As the main process of the container, it can respond to signals sent to the container.

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