您好,登錄后才能下訂單哦!
本篇文章為大家展示了springboot中怎么使用maven構(gòu)建docker鏡像,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
首先注冊(cè)阿里云鏡像倉庫,新建倉庫,并獲得倉庫公網(wǎng)地址.
registry.cn-shanghai.aliyuncs.com/smartlife-docker/deploy
此處,需要注意,鏡像倉庫有密碼,需要在首頁進(jìn)行密碼重置.頁面顯示使用登錄密碼即可,但是實(shí)際使用中還是要重置一次比較靠譜.
以下為本地操作.
首先配置 maven 的 setting.xml
添加如下內(nèi)容
<server> <id>docker</id> <!--此處為配置ID信息--> <username>a@a.com</username> <!--用戶名--> <password>123123</password> <!--密碼--> <configuration> <email>a@a.com</email> <!--對(duì)應(yīng)用戶名--> </configuration> </server>
下面在程序中新增dockerfile,構(gòu)建docker鏡像
# Version 0.0.1 FROM java:8 VOLUME /data/deploy/tmp ADD @project.build.finalName@.@project.packaging@ app.jar RUN sh -c 'touch /app.jar' EXPOSE 7074 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
dockerfile文件位于
/src/main/docker/
修改pom文件
<docker.image.prefix>鏡像名</docker.image.prefix> <docker.repostory>阿里云倉庫地址</docker.repostory> <docker.registry.name>命名空間</docker.registry.name>
在build部分增加
docker-maven-plugin
插件
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.13</version> <!--配置使用mvn clean package的同時(shí)進(jìn)行docker構(gòu)建--> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <skipDocker>false</skipDocker> <!-- 私有倉庫配置,需要settings.xml文件配合serverId對(duì)應(yīng)的服務(wù)地址 --> <serverId>docker-aliyun</serverId> <registryUrl>${docker.repostory}/${docker.registry.name}/${project.name}</registryUrl> <!-- <forceTags>true</forceTags> --> <!--install階段也上傳,否則只有deploy階段上傳--> <pushImage>true</pushImage> <dockerDirectory>target/docker</dockerDirectory> <imageName> ${docker.repostory}/${docker.registry.name}/${project.name}:${project.version} </imageName> <dockerHost>http://192.168.125.245:2375</dockerHost> <resources> <rescource><!-- 將打包文件放入dockerDirectory指定的位置 --> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </rescource> </resources> </configuration> </plugin>
在 build節(jié)點(diǎn)下增加 resources節(jié)點(diǎn)
<resources> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> </resource> <resource> <directory>src/main/docker</directory> <filtering>true</filtering> <includes> <include>**/Dockerfile</include> </includes> <targetPath>../docker</targetPath> </resource> </resources>
上述內(nèi)容就是springboot中怎么使用maven構(gòu)建docker鏡像,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。