如何在 Dockerfile 中更改 war 文件的应用程序属性
How to change application properties of war file in Dockerfile
我有一个 Springboot 应用程序的 jar/war 文件,它包括 application.properties 文件(在 Dev 环境中有到数据库的连接设置,位于文件夹 src\main\resources,我使用 hikari数据源)。现在,我想在创建 Dockerfile 时修改此属性文件,为 UAT 环境构建映像。我该怎么做?
这是我的 Dockerfile:
FROM openjdk:8
VOLUME /tmp
ADD target/springboot-docker-mysql.jar springboot-docker-mysql.jar
EXPOSE 8083
ENTRYPOINT ["java","-jar","springboot-docker-mysql.jar"]
这是我的属性文件:
## Spring DATA SOURCE Configurations
#spring.datasource.url = jdbc:mysql://localhost:3306/test?useSSL=false
#spring.datasource.url = jdbc:mysql://mysql-standalone:3306/test?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&useSSL=false
spring.datasource.url = jdbc:mysql://mysql-standalone-p-lggjt-mysql.mysql-standalone-p-lggjt.svc.cluster.local:3306/test?useSSL=false
spring.datasource.username = testuser
spring.datasource.password = testuser@123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = create
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
server.port=8083
改变你的Dockerfile
FROM openjdk:8
VOLUME /tmp
WORKDIR /
ADD target/springboot-docker-mysql.jar springboot-docker-mysql.jar
ENTRYPOINT ["java","-jar","springboot-docker-mysql.jar","--spring.config.additional-location=application.properties"]
更改docker run
命令:
docker run --name my-app --restart always -it -d -p 8083:8083 -v $PWD/application.properties:/application.properties my-app:v1
注意: $PWD/application.properties
是您的应用程序属性文件,您正在将其安装在容器内的 /application.properties
位置。我们还对 dockerfile 进行了轻微更改,并使用 --spring.config.additional-location
选项指向 application.properties.
要了解有关 --spring.config.additional-location
的更多信息,请查看 this。
我有一个 Springboot 应用程序的 jar/war 文件,它包括 application.properties 文件(在 Dev 环境中有到数据库的连接设置,位于文件夹 src\main\resources,我使用 hikari数据源)。现在,我想在创建 Dockerfile 时修改此属性文件,为 UAT 环境构建映像。我该怎么做?
这是我的 Dockerfile:
FROM openjdk:8
VOLUME /tmp
ADD target/springboot-docker-mysql.jar springboot-docker-mysql.jar
EXPOSE 8083
ENTRYPOINT ["java","-jar","springboot-docker-mysql.jar"]
这是我的属性文件:
## Spring DATA SOURCE Configurations
#spring.datasource.url = jdbc:mysql://localhost:3306/test?useSSL=false
#spring.datasource.url = jdbc:mysql://mysql-standalone:3306/test?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&useSSL=false
spring.datasource.url = jdbc:mysql://mysql-standalone-p-lggjt-mysql.mysql-standalone-p-lggjt.svc.cluster.local:3306/test?useSSL=false
spring.datasource.username = testuser
spring.datasource.password = testuser@123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = create
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
server.port=8083
改变你的Dockerfile
FROM openjdk:8
VOLUME /tmp
WORKDIR /
ADD target/springboot-docker-mysql.jar springboot-docker-mysql.jar
ENTRYPOINT ["java","-jar","springboot-docker-mysql.jar","--spring.config.additional-location=application.properties"]
更改docker run
命令:
docker run --name my-app --restart always -it -d -p 8083:8083 -v $PWD/application.properties:/application.properties my-app:v1
注意: $PWD/application.properties
是您的应用程序属性文件,您正在将其安装在容器内的 /application.properties
位置。我们还对 dockerfile 进行了轻微更改,并使用 --spring.config.additional-location
选项指向 application.properties.
要了解有关 --spring.config.additional-location
的更多信息,请查看 this。