I have .env
file and I can't run docker-compose.yml
at remote server, I can not inject any environment variable to make the application able to integrate with another docker with database:
# stage 1
FROM eclipse-temurin:8-alpine AS build
ENV HOME=/usr/app
RUN mkdir -p $HOME
WORKDIR $HOME
ADD . $HOME
RUN --mount=type=cache,target=/root/.m2 ./mvnw -f $HOME/pom.xml clean install
# stage 2
FROM eclipse-temurin:8-alpine
ARG JAR_FILE=/usr/app/target/*.jar
COPY --from=build $JAR_FILE /app/runner.jar
ARG ENV_FILE=/usr/app/.env
COPY --from=build $ENV_FILE /app/.env
ARG INIT_FILE=/usr/app/contextinit.sh
COPY --from=build $INIT_FILE /app/contextinit.sh
RUN chmod +x /app/contextinit.sh
CMD ["/bin/bash","/app/contextinit.sh"]
ENTRYPOINT java -jar -Dspring.profiles.active=prod /app/runner.jar
the content mentioned above contextinit.sh
is: set -a && . .env && set +a
of course.
How to inject credentials to make it available for dockerized spring application started at ENTRYPOINT
? Spring app runs successfully, but without necessary context. Unfortunately the good working docker-compose.yml
is not recognized on the remote server, so I plan to do everything in Dockerfile
only.