I've a spring boot app that I'm deploying in a Tomcat Docker.
I've many properties in application-deploy.properties
like this:
#DB
spring.datasource.url=jdbc:mysql://${SPRING_DATASOURCE_URL}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
I want to get the variables from Docker. So, I'm trying this Dockerfile
:
FROM tomcat:9.0.56
ARG SPRING_DATASOURCE_URL
ARG SPRING_DATASOURCE_USERNAME
ARG SPRING_DATASOURCE_PASSWORD
COPY setenv.sh /usr/local/tomcat/bin/setenv.sh
COPY /app/target/api.war /usr/local/tomcat/webapps/ROOT.war
EXPOSE 8080
CMD ["catalina.sh", "run"]
and I've setenv.sh
like this:
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=deploy"
JAVA_OPTS="$JAVA_OPTS -DSPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL}"
JAVA_OPTS="$JAVA_OPTS -DSPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME}"
JAVA_OPTS="$JAVA_OPTS -DSPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD}"
Any idea of what I'm wrong and how can solve it? I want to pass the variables to application-deploy.properties when I build Docker.
CodePudding user response:
Use the ENV
Statement.
ENV SPRING_DATASOURCE_URL="MY_ACTUAL_URL"
ENV SPRING_DATASOURCE_USERNAME="user"
ENV SPRING_DATASOURCE_PASSWORD="pw"
CodePudding user response:
You can pass in the environment variables via
docker run -e SPRING_DATASOURCE_URL="" -e SPRING_DATASOURCE_USERNAME="" --name {container-name} {image-name}