Skip to content

Instantly share code, notes, and snippets.

@initcron
Created November 3, 2022 16:36
Show Gist options
  • Save initcron/f0dc29383836dc8f0f41c796c56ddd9d to your computer and use it in GitHub Desktop.
Save initcron/f0dc29383836dc8f0f41c796c56ddd9d to your computer and use it in GitHub Desktop.
How to add a delay to start the service with Docker.

Step 1: Create a file ep.sh with the following content,

#!/bin/sh

echo "I: Sleeping for 20seconds....."
sleep 20

exec "$@"

Step 2: Make this script executable

chmod +x ep.sh

Step 3: Update Dockerfile to copy over and make use of the entrypoint

FROM schoolofdevops/maven:spring AS BUILD
WORKDIR /app
COPY . .
RUN mvn spring-javaformat:apply && \
    mvn package -DskipTests

FROM openjdk:8-alpine AS PKG
WORKDIR /run
COPY --from=BUILD /app/target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /run/petclinic.jar
EXPOSE 8080
COPY ep.sh /usr/local/bin/ep.sh
ENTRYPOINT ["ep.sh"]
CMD java -jar petclinic.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment