基础镜像用alpine 因为他小,有包管理器
dockerfile如下
# AlpineLinux open jre 7FROM alpine:latest# Install cURLRUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main\n\https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community" > /etc/apk/repositoriesRUN apk --update add curl bash openjdk7-jre-base && \ rm -rf /var/cache/apk/*# Set environmentENV JAVA_HOME /usr/lib/jvm/default-jvmENV PATH ${PATH}:${JAVA_HOME}/bin
安装oracle jre 太麻烦,有臃肿,还缺少库文件,直接openjdk
构建镜像
docker build -t alpine-jdk7 -f alpine_jdk7 .
alpine-jdk7 是镜像的名字,我没打tag
-f 后面跟的是dockerfile 的名字,重要的是后面不要忘了那个“ .” 不然无法构建
现在构建一个完整的java 应用环境 alpine-tomcat7-jdk7 java 环境可以根据需要自己换下
# AlpineLinux open jre 7FROM alpine:latest# Install cURLRUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main\n\https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community" > /etc/apk/repositoriesRUN apk --update add curl bash openjdk7-jre-base && \ rm -rf /var/cache/apk/*# Set environmentENV JAVA_HOME /usr/lib/jvm/default-jvmENV PATH ${PATH}:${JAVA_HOME}/binADD ./apache-tomcat7 /home/apache-tomcat7
抄个别人的dockerfile
FROM alpineMAINTAINER ××××××××RUN echo '@edge http://nl.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories && \ echo '@community http://nl.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories && \ apk update && \ apk upgrade && \ apk add ca-certificates openjdk8-jre-base@community && \ apk del ca-certificates && \ rm -rf /tmp/* /var/cache/apk/*