为 MySQL/Tomcat/Maven Java Webapp 创建 Docker 文件



我们如何为 MySQL/Tomcat/Maven 项目创建 DockerFile。

到目前为止,我已经设法为春季启动应用程序构建了DockerFile,该应用程序使用以下代码内置了tomcat:

#FROM openjdk:8-jdk-alpine
FROM openjdk:8-jre-alpine
#VOLUME /tmp
COPY target/notifier-0.0.1-SNAPSHOT.jar /notifier.jar
CMD [ "/usr/bin/java", "-jar", "-Dspring.profiles.active=test", "/notifier.jar" ]
#Build command => docker build -f DockerFile -t notifier:latest .
#RUN command => docker run -p 9090:8072 notifier
#Image Path => ~/Library/Containers/com.docker.docker/Data/...
#Save Image Locally => docker save -o notifier.tar notifier
#Load Image Locally => docker load -i notifier.tar notifier
#Run Image Locally => docker run -d --restart=always -p newport:original_port notifier

但是现在我想使用单独的 mysql/tomcat 我需要添加到此或任何参考资源中的哪些更改将很有帮助。

您可以将docker-compose.yml与每个组件的容器一起使用:

version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
whatever-other-service:
image: whateverimage
restart: always
ports:
- 8080:8080

并使用docker-compose up启动

在 Dockerfile 中使用此图像(mysql、tomcat、ant 和 maven(

From guligo/jdk-maven-ant-tomcat-mysql

最新更新