[Docker] Link the Java application and database Docker containers

application-mysql.properties:

spring.datasource.url=jdbc:mysql://ec-mysql:3306/explorecali
spring.datasource.username=cali_user
spring.datasource.password=cali_pass

 

Dockerfile: run with profile

FROM java:8
WORKDIR /
ADD target/explorecali-2.0.0-SNAPSHOT.jar //
EXPOSE 8080
ENTRYPOINT
[ "java",
"-jar",
"-Dspring.profiles.active=mysql",
"/explorecali-3.0.0-SNAPSHOT.jar"]

 

Build the applciation:

mvn package -DskipTests=true

 

Build the image:

docker build -t explorecali .

 

Link mysql image to application image:

docker run --name ec-app -p 8080:8080 --link ec-mysql:mysql -d explorecali

 

posted @ 2020-12-27 22:44  Zhentiw  阅读(73)  评论(0编辑  收藏  举报