1. 程式人生 > >docker用maven構建和啟動一個springboot專案

docker用maven構建和啟動一個springboot專案

maven外掛構建一個docker映象1.maven配置<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.12</version> <configuration> <!-- 注意imageName一定要是符合正則[a-z0-9-_.]的,否則構建不會成功 --> <!-- 詳見:https://github.com/spotify/docker-maven-plugin Invalid repository name ... only [a-z0-9-_.] are allowed--> <imageName>eurekaserver</imageName> <baseImage>java</baseImage> <entryPoint>[ "sh", "-c", "java $JAVA_OPTS -jar /${project.build.finalName}.jar" ] </entryPoint> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin>2.在linux上執行命令mvn clean package docker:build3.執行docker映象docker run -d -p 1111:1111 -e JAVA_OPTS='-Dspring.profiles.active=peer1' eureka-d表示後臺執行-p表示埠對映-e jvm引數設定,包含了配置檔案切換的'-Dspring.profiles.active=peer1上面這條啟動命令是有兩個配置檔案application-peer1.properties,application-peer2.properties的情況