摘要:比如該目錄下有,則對應該鏡像目錄為打包使用是在本地打包鏡像,不到遠程,參數是顯示信息如果使用命令,則打包之后到遠程輸出日志實例查看鏡像可以看到指定了這三個文件夾小結默認執行如下操作也就是將拷貝到,將拷貝到,將拷貝到
序
本文主要研究一下如何使用google的jib打包docker鏡像
maven配置com.google.cloud.tools jib-maven-plugin 0.9.9
UTF-8 UTF-8 1.8 yyyyMMdd org.springframework.boot spring-boot-maven-plugin com.google.cloud.tools jib-maven-plugin 0.9.9 -Xms512m 8080 true java:8u172-jre-alpine jib-demo:${maven.build.timestamp} true ${project.basedir}/src/main/jib
這里指定base image為java:8u172-jre-alpine
同時指定生成的image名稱為jib-demo:${maven.build.timestamp}
container標簽可以指定相關參數,比如jvmFlags指定JVM參數,ports指定expose的端口號
extraDirectory用于指定要添加的目錄,默認為${project.basedir}/src/main/jib,即該目錄下的文件夾會在docker鏡像里頭同步創建,目錄層級關系以jib下目錄層級關系為準。比如該目錄下有app/resources/demo.txt,則對應該鏡像目錄為/app/resources/demo.txt
打包mvn compile jib:dockerBuild -X
使用jib:dockerBuild是在本地打包鏡像,不push到遠程,-X參數是顯示debug信息
如果使用jib:build命令,則打包之后push到遠程
輸出日志實例:
[DEBUG] TIMING Building image to Docker daemon [DEBUG] RUNNING Building image to Docker daemon [INFO] Getting base image java:8u172-jre-alpine... [DEBUG] TIMING Pulling base image manifest [DEBUG] RUNNING Pulling base image manifest [DEBUG] TIMING Building application layers [DEBUG] RUNNING Building application layers [INFO] Building dependencies layer... [DEBUG] TIMING Building dependencies layer [DEBUG] RUNNING Building dependencies layer [INFO] Building resources layer... [DEBUG] TIMING Building resources layer [DEBUG] RUNNING Building resources layer [INFO] Building classes layer... [DEBUG] TIMING Building classes layer [DEBUG] RUNNING Building classes layer [INFO] Building extra files layer... [DEBUG] TIMING Building extra files layer [DEBUG] RUNNING Building extra files layer [DEBUG] TIMED Building application layers : 3.498 ms [DEBUG] Building application layers : 3.498 ms [DEBUG] Building extra files layer built sha256:0a9321c621ee2c138d9a93f4ba47f825e20dd7aca0e9206f30bf560122fdaa31 [DEBUG] Building resources layer built sha256:933116c8da4db70000355b750af2f3b5c4545e74db7b5eb0a5e37689ef86d44f [DEBUG] Building classes layer built sha256:a99dbde7d015ba3d15b9265ac38f6536d65b00dd2a864b7003a34742f483939b [DEBUG] TIMED Building extra files layer : 33.718 ms [DEBUG] TIMED Building classes layer : 33.901 ms [DEBUG] Building extra files layer : 33.718 ms [DEBUG] TIMED Building resources layer : 34.062 ms [DEBUG] Building resources layer : 34.062 ms [DEBUG] Building classes layer : 33.901 ms [DEBUG] Building dependencies layer built sha256:a19961ec08095eb70ca3a070945223dcf51500a255a745272276139bf0a29f4e [DEBUG] TIMED Building dependencies layer : 1047.83 ms [DEBUG] Building dependencies layer : 1047.83 ms [INFO] The base image requires auth. Trying again for java:8u172-jre-alpine... //...... [DEBUG] TIMED Pulling base image manifest : 8959.891 ms [DEBUG] Pulling base image manifest : 8959.891 ms [DEBUG] TIMING Setting up base image caching [DEBUG] RUNNING Setting up base image caching [DEBUG] TIMED Setting up base image caching : 0.824 ms [DEBUG] Setting up base image caching : 0.824 ms [DEBUG] TIMING Pulling base image layer sha256:500c0ac4cdc58aee9a008e70466eeec8a4b74b25c29d003764635d2fe1b42827 [DEBUG] RUNNING Pulling base image layer sha256:500c0ac4cdc58aee9a008e70466eeec8a4b74b25c29d003764635d2fe1b42827 [DEBUG] TIMING Pulling base image layer sha256:aa38cd8c77d7320c7489327775e074580db5f23467198aab3e79c7db5cdfbdca [DEBUG] TIMING Pulling base image layer sha256:cb56d62302ec31640b40ca15843e7af6be145966a1064c78ea7afd6f10ce49e6 [DEBUG] RUNNING Pulling base image layer sha256:cb56d62302ec31640b40ca15843e7af6be145966a1064c78ea7afd6f10ce49e6 [DEBUG] TIMING Pulling base image layer sha256:ff3a5c916c92643ff77519ffa742d3ec61b7f591b6b7504599d95a4a41134e28 [DEBUG] RUNNING Pulling base image layer sha256:ff3a5c916c92643ff77519ffa742d3ec61b7f591b6b7504599d95a4a41134e28 [DEBUG] RUNNING Pulling base image layer sha256:aa38cd8c77d7320c7489327775e074580db5f23467198aab3e79c7db5cdfbdca [DEBUG] TIMED Pulling base image layer sha256:500c0ac4cdc58aee9a008e70466eeec8a4b74b25c29d003764635d2fe1b42827 : 612.524 ms [DEBUG] Pulling base image layer sha256:500c0ac4cdc58aee9a008e70466eeec8a4b74b25c29d003764635d2fe1b42827 : 612.524 ms [DEBUG] TIMED Pulling base image layer sha256:ff3a5c916c92643ff77519ffa742d3ec61b7f591b6b7504599d95a4a41134e28 : 9985.702 ms [DEBUG] Pulling base image layer sha256:ff3a5c916c92643ff77519ffa742d3ec61b7f591b6b7504599d95a4a41134e28 : 9985.702 ms [DEBUG] TIMED Pulling base image layer sha256:aa38cd8c77d7320c7489327775e074580db5f23467198aab3e79c7db5cdfbdca : 27267.144 ms [DEBUG] Pulling base image layer sha256:aa38cd8c77d7320c7489327775e074580db5f23467198aab3e79c7db5cdfbdca : 27267.144 ms [DEBUG] TIMED Pulling base image layer sha256:cb56d62302ec31640b40ca15843e7af6be145966a1064c78ea7afd6f10ce49e6 : 54734.971 ms [DEBUG] Pulling base image layer sha256:cb56d62302ec31640b40ca15843e7af6be145966a1064c78ea7afd6f10ce49e6 : 54734.971 ms [DEBUG] TIMING Building container configuration [DEBUG] RUNNING Building container configuration [INFO] Finalizing... [DEBUG] TIMED Building container configuration : 0.462 ms [DEBUG] Building container configuration : 0.462 ms [INFO] Loading to Docker daemon... [DEBUG] TIMED Building image to Docker daemon : 65862.956 ms [DEBUG] Building image to Docker daemon : 65862.956 ms [INFO] [INFO] Container entrypoint set to [java, -Xms512m, -cp, /app/resources/:/app/classes/:/app/libs/*, com.example.JibDemoApplication] [INFO] [INFO] Built image to Docker daemon as jib-demo:20180826 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:07 min [INFO] Finished at: 2018-08-26T21:38:11+08:00 [INFO] Final Memory: 26M/493M [INFO] ------------------------------------------------------------------------查看鏡像
docker inspect jib-demo:20180826 [ { "Id": "sha256:7554492dde84091bc6d015b29ec4bf854bb841b9ec4d8f7bef8b51a8ec59ef94", "RepoTags": [ "jib-demo:20180826" ], "RepoDigests": [], "Parent": "", "Comment": "", "Created": "2018-08-26T13:37:05.65Z", "Container": "", "ContainerConfig": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": null, "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "DockerVersion": "", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "8080/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/opt/jdk1.8.0_172/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "JAVA_HOME=/opt/jdk1.8.0_172" ], "Cmd": [], "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": [ "java", "-Xms512m", "-cp", "/app/resources/:/app/classes/:/app/libs/*", "com.example.JibDemoApplication" ], "OnBuild": null, "Labels": {} }, "Architecture": "amd64", "Os": "linux", "Size": 186079594, "VirtualSize": 186079594, "GraphDriver": { "Data": null, "Name": "aufs" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:cd7100a72410606589a54b932cabd804a17f9ae5b42a1882bd56d263e02b6215", "sha256:317e0b42ef29551507adc792c2dbc389af85c5d68900cf0f08abe907cbd4e199", "sha256:d6fd5302a9ee64c43b46153e9678153819d6d0e247381acbbe6cbe6ed9de0366", "sha256:417c6bd0930eb69d17ae5d601898a6a012900ca33c69e612840a3042b2451cbb", "sha256:8309a5eed5158c5639acb664312ddc7027a2ecb172744f548d6d9fb5f918a744", "sha256:6ef8c795d7a5e2a07f51d572a90b820e089f89adf30798193f4f3f410a261415", "sha256:9990447f3d37e3f2dc70718d0ea6602cf7843091d8bbe395f552c9c5dd10551c", "sha256:ff7910aaeee962d1d86e00742030378a2758da59d8c8cda3fe44314bbffffd8081" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ]
可以看到java -cp指定了/app/libs/、/app/resources/、/app/classes/這三個文件夾
小結jib默認執行如下操作
COPY libs /app/libs/ COPY resources /app/resources/ COPY classes /app/classes/
也就是將libs拷貝到/app/libs,將resources拷貝到/app/resources,將classes拷貝到/app/classes.doc
jib
Building Docker Image for a Spring Boot App With Jib
build-containers-faster-with-jib-a-google-image-build-tool-for-java-applications
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/27417.html
摘要:在年下旬開源了一款新的工具,可以輕松地將應用程序容器化。由于默認訪問谷歌的倉庫,而國內訪問不穩定會經常導致網絡超時,所以筆者使用了國內的阿里云鏡像服務,那么就不需要訪問谷歌的倉庫了。執行完成后,我們可以在阿里云鏡像倉庫獲取鏡像。 原文地址:梁桂釗的博客博客地址:http://blog.720ui.com 歡迎關注公眾號:「服務端思維」。一群同頻者,一起成長,一起精進,打破認知的局限性。...
摘要:在年下旬開源了一款新的工具,可以輕松地將應用程序容器化。由于默認訪問谷歌的倉庫,而國內訪問不穩定會經常導致網絡超時,所以筆者使用了國內的阿里云鏡像服務,那么就不需要訪問谷歌的倉庫了。執行完成后,我們可以在阿里云鏡像倉庫獲取鏡像。 原文地址:梁桂釗的博客博客地址:http://blog.720ui.com 歡迎關注公眾號:「服務端思維」。一群同頻者,一起成長,一起精進,打破認知的局限性。...
摘要:今天逛了逛,順手精選出了一下近幾個月以來上最熱門的個項目。相關閱讀正式開源,幫助應用快速容器化未來可能會上熱門的項目地址介紹哈哈,皮一下很開心。這是我自己開源的一份文檔,目前仍在完善中,歡迎各位英雄好漢一起完善。 showImg(https://segmentfault.com/img/remote/1460000015766827?w=391&h=220);今天逛了逛Github,順...
摘要:本文將介紹精簡容器鏡像的必要性并以基于的應用為例描述最小化容器鏡像的常用技巧。經過這一優化,最終鏡像的大小為。 背景 隨著容器技術的普及,越來越多的應用被容器化。人們使用容器的頻率越來越高,但常常忽略一個基本但又非常重要的問題 - 容器鏡像的體積。本文將介紹精簡容器鏡像的必要性并以基于 spring boot 的 java 應用為例描述最小化容器鏡像的常用技巧。 精簡容器鏡像的必要性 ...
閱讀 3077·2023-04-26 00:53
閱讀 3522·2021-11-19 09:58
閱讀 1693·2021-09-29 09:35
閱讀 3279·2021-09-28 09:46
閱讀 3852·2021-09-22 15:38
閱讀 2692·2019-08-30 15:55
閱讀 3006·2019-08-23 14:10
閱讀 3822·2019-08-22 18:17