- 快召唤伙伴们来围观吧
- 微博 QQ QQ空间 贴吧
- 文档嵌入链接
- 复制
- 微信扫一扫分享
- 已成功复制到剪贴板
用 Jib 将 Kubernetes 的 Java 应用程序容器化
展开查看详情
1 . A container image builder for Java applications Build containers faster with Jib github.com/GoogleContainerTools/jib
2 . Our Team Cloud Tools for Java Appu Goundan Qingyang “Q” Chen @loosebazooka @coollog
3 .Containers “Write once, run anywhere” github.com/GoogleContainerTools/jib
4 . Building a Java container github.com/GoogleContainerTools/jib
5 . Me Java Developer Building website for pet clinic Wants to containerize the backend Wants container on registry ilovejava.io/petclinic-app github.com/GoogleContainerTools/jib
6 .github.com/GoogleContainerTools/jib
7 .构建Java镜像 github.com/GoogleContainerTools/jib
8 .So I read some tutorials
9 .FROM ubuntu:14.04 RUN apt-get update && apt-get install -y python-software-properties software-properties-common RUN add-apt-repository ppa:webupd8team/java RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 boolean true"| debconf-set-selections RUN apt-get update && apt-get install -y oracle-java8-installer maven ADD . /usr/local/petclinic RUN cd /usr/local/petclinic && mvn install CMD ["/usr/bin/java", "-cp", "/usr/local/petclinic/target/petclinic-1.0.jar" , "petclinic.WebServer"] github.com/GoogleContainerTools/jib
10 .So I read some more tutorials
11 .FROM openjdk:8 COPY target/petclinic-*.jar /app.jar ENTRYPOINT java -jar /app.jar github.com/GoogleContainerTools/jib
12 .FROM openjdk:8 COPY target/petclinic-*.jar /app.jar ENTRYPOINT java -jar /app.jar Problem: openjdk:8 is 284MB github.com/GoogleContainerTools/jib
13 .Some more searching
14 .FROM openjdk:8-jre-alpine 82 MB COPY target/petclinic-*.jar /app.jar ENTRYPOINT java -jar /app.jar github.com/GoogleContainerTools/jib
15 .Dockerfile best practices github.com/GoogleContainerTools/jib
16 .docs.docker.com/develop/develop-images/dockerfile_best-practices github.com/GoogleContainerTools/jib
17 ..dockerignore ** !target/petclinic-*.jar github.com/GoogleContainerTools/jib
18 .Some more tutorials later
19 .$ mvn dependencies:copy-dependencies to target/dependencies/ FROM openjdk:8-jre-alpine COPY target/dependencies /app/dependencies COPY target/classes /app/classes ENTRYPOINT java -cp /app/dependencies/*:/app/classes petclinic.WebServer github.com/GoogleContainerTools/jib
20 .Some more searching
21 . ... <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.4.8</version> <configuration> <repository>ilovejava.io/petclinic-app</repository> <tag>${project.version}</tag> </configuration> </plugin> </plugins> </build> ... github.com/GoogleContainerTools/jib
22 .What did we 1. 2. Write first Dockerfile Reduce image size do? 3. Don’t run installs 4. Use better base image 5. Write .dockerignore 6. Improve incremental speed 7. Switch to use a Maven plugin github.com/GoogleContainerTools/jib
23 . cker nd install Do Download a What did we 1. 2. Write first Dockerfile Reduce image size do? 3. Don’t run installs 4. Use better base image 5. Write .dockerignore 6. Improve incremental speed 7. Switch to use a Maven plugin github.com/GoogleContainerTools/jib
24 . cker nd install Do Download a What did we 1. 2. Write first Dockerfile Reduce image size Order of layers to optimize for cache hits do? 3. Don’t run installs 4. Use better base image 5. Write .dockerignore 6. Improve incremental speed 7. Switch to use a Maven plugin github.com/GoogleContainerTools/jib
25 . cker nd install Do Download a What did we 1. 2. Write first Dockerfile Reduce image size Order of layers to optimize for cache hits do? 3. Don’t run installs 4. Use better base image ilds e bu ag 5. Write .dockerignore st lti- f mu eo 6. Improve incremental speed Us 7. Switch to use a Maven plugin github.com/GoogleContainerTools/jib
26 .Understanding Docker cker cache mechanism an nd install Do d quirks Download a What did we 1. 2. Write first Dockerfile Reduce image size Order of layers to optimize for cache hits do? 3. Don’t run installs 4. Use better base image ilds e bu ag 5. Write .dockerignore st lti- f mu eo 6. Improve incremental speed Us 7. Switch to use a Maven plugin github.com/GoogleContainerTools/jib
27 .Understanding Docker cker cache mechanism an nd install Do d quirks Download a What did we 1. 2. Write first Dockerfile Reduce image size Order of layers to optimize for cache hits do? 3. Don’t run installs 4. Use better base image ilds e bu aemo n sta g 5. Write .dockerignore cker d lti- to run Do mu rivileges of 6. Improve incremental speed ted p e eleva Us Have 7. Switch to use a Maven plugin github.com/GoogleContainerTools/jib
28 .Understanding Docker cker cache mechanism an nd install Do d quirks Download a What did we 1. 2. Write first Dockerfile Reduce image size Order of layers to optimize for cache hits do? 3. Don’t run installs 4. Use better base image ilds e bu aemo n sta g 5. Write .dockerignore cker d lti- to run Do mu rivileges of 6. Improve incremental speed ted p e eleva Us Have 7. Switch to use a Maven plugin saturnism.me/talk/docker-tips-and-tricks github.com/GoogleContainerTools/jib
29 .Containerizing with Docker build Project JAR send build Docker Container docker Daemon Image Dockerfile push Registry github.com/GoogleContainerTools/jib