赞
踩
前面尝试使用基础依赖镜像java:8(FROM java:8)直接构建java springboot项目镜像,发现一个简单的REST接口的springboot服务,生成的镜像竟然高达667M;
- REPOSITORY TAG IMAGE ID CREATED SIZE
- docker.io/http-server v2.0.0 bed3abdf0002 6 days ago 667 MB
- docker.io/java 8 d23bdf5b1b1b 2 years ago 643 MB
当然了,我们依赖的这个java:8本身就有643M,而且这个基础镜像做成的容器里面,要啥啥没有,没有vi,没有vim,没有yum,没有curl 。。。 。。。
于是我就尝试在Github上参考了几个使用各种linux版本制作的java基础镜像,
- java.sh
-
- export JAVA_HOME=/usr
1、java_alpine (openjdk version "1.8.0_212")
- FROM alpine:latest
- MAINTAINER from Github
-
- LABEL Description="Alpine Java (OpenJDK)"
-
- ARG JAVA_VERSION=8
- ARG JAVA_RELEASE=JDK
-
- RUN set -euxo pipefail && \
- pkg="openjdk$JAVA_VERSION" && \
- if [ "$JAVA_RELEASE" != "JDK" ]; then \
- pkg="$pkg-jre"; \
- fi && \
- apk add --no-cache $pkg
-
- COPY profile.d/java.sh /etc/profile.d/
-
- ENV JAVA_HOME=/usr
-
- CMD /bin/sh
做成的镜像有105M (有vi,无vim,无apt-get)
alpine_java8 latest da4060d79e60 47 hours ago 105 MB
2、centos_java8 (openjdk version "1.8.0_222")
- FROM centos:latest
- MAINTAINER from Github
-
- LABEL Description="Java + CentOS (OpenJDK)"
-
- ARG JAVA_VERSION=8
- ARG JAVA_RELEASE=JDK
-
- RUN set -euxo pipefail && \
- pkg="java-1.$JAVA_VERSION.0-openjdk" && \
- if [ "$JAVA_RELEASE" = "JDK" ]; then \
- pkg="$pkg-devel"; \
- else \
- pkg="$pkg-headless"; \
- fi; \
- yum install -y "$pkg" && \
- yum clean all && \
- rm -rf /var/cache/yum
-
- COPY profile.d/java.sh /etc/profile.d/
-
- ENV JAVA_HOME=/usr
-
- CMD /bin/bash
做成的镜像有455M (有vi,无vim,无apt-get,有yum,有curl)
centos_java8 latest b8b426a4903f 2 days ago 455 MB
3、java_debian (openjdk version "1.8.0_222")
- FROM debian:stretch
- MAINTAINER from Github
-
- LABEL Description="Java + Debian (OpenJDK)"
-
- ENV DEBIAN_FRONTEND noninteractive
-
- ARG JAVA_VERSION=8
- ARG JAVA_RELEASE=JRE
-
- RUN bash -c ' \
- set -euxo pipefail && \
- apt-get update && \
- pkg="openjdk-$JAVA_VERSION"; \
- if [ "$JAVA_RELEASE" = "JDK" ]; then \
- pkg="$pkg-jdk"; \
- else \
- pkg="$pkg-jre-headless"; \
- fi; \
- apt-get install -y --no-install-recommends "$pkg" && \
- apt-get clean \
- '
-
- COPY profile.d/java.sh /etc/profile.d/
-
- ENV JAVA_HOME=/usr
-
- CMD /bin/bash
做成的镜像有269M (无vi,无vim)
debian_java8 latest dbf6cbd2c40e 47 hours ago 269 MB
4、java_ubuntu (openjdk version "1.8.0_222")
- FROM ubuntu:latest
- MAINTAINER from Github
-
- LABEL Description="Java + Ubuntu (OpenJDK)"
-
- ENV DEBIAN_FRONTEND noninteractive
-
- ARG JAVA_VERSION=8
- ARG JAVA_RELEASE=JDK
-
- RUN bash -c ' \
- set -euxo pipefail && \
- apt-get update && \
- pkg="openjdk-$JAVA_VERSION"; \
- if [ "$JAVA_RELEASE" = "JDK" ]; then \
- pkg="$pkg-jdk-headless"; \
- else \
- pkg="$pkg-jre-headless"; \
- fi; \
- apt-get install -y --no-install-recommends "$pkg" && \
- apt-get clean'
-
- COPY profile.d/java.sh /etc/profile.d/
-
- ENV JAVA_HOME=/usr
-
- CMD /bin/bash
做成的镜像有275M (无vi,无vim,有apt-get)
ubuntu_java8 latest afcc6eea4c50 47 hours ago 275 MB
5、其他
尝试了其他的依赖镜像如:
- docker.io/openjdk 8-jre-alpine f7a292bbb70c 3 months ago 84.9 MB
- docker.io/openjdk 8-jdk-alpine a3562aa0b991 3 months ago 105 MB
启动简单的java应用是没有问题的,体积小启动快,推荐 好用
启动复杂的java应用的时候,会发生各种不可思议的问题,可能跟缺少一下必要的系统依赖有关系,需要关注这一点。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。