1、今天有空看了一篇公众号docker 部署SpringBoot项目
2、刚好自己手上有spring boot 项目那就试下
3、不多说了那就干吧
1、先要有安装docker ,maven
1.2、拉取jdk1.8
docker pull java:8
2、安装好docker spring boot 项目的pom.xml文件需要加
<properties> <docker.image.prefix>registry.aliyuncs.com/linhuatest</docker.image.prefix>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<!--docker文件所在的目录-->
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
3、在spring boot 项目的main目录下建目录与文件夹
docker file 内容如下
FROM java:8
VOLUME /tmp/tomcat
ADD oxx_datacenter_xxx-0.0.1-SNAPSHOT.jar springboot-docker.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/springboot-docker.jar"]
说明:FROM:指定存在的镜像,java:8是我刚刚拉取的镜像,运行的基础。VOLUME:指向的一个临时文件,用于存储tomcat工作。ADD:复制文件并且重命名文件。ENTRYPOINT:初始化配置或者自定义配置。
4、然后进入spring boot 目录下 cd
/Users/liyang/Downloads//oxx_datacenter_xxx
5、执行命令
mvn clean package docker:build
6、查看生成的docker 文件
docker images
7、运行文件(注意项目的端口号最好和你spring boot 中的 .yml一样)
docker run --name xxx_datacenter_xxx -p 28075:28075 -d c25b
8、查看起来了没有
docker ps
9、进入容器
docker exec -it 3cf2 /bin/bash
10、查看日志,这里的日志位置与你的spring boot中的log4j 配置的目录是一级的运行ok
参考的公众号地址:https://mp.weixin.qq.com/s/I-qREIU35QoV0tzCxB1hnQ