编写dockerfile实现项目自动运行
我们打包项目,因为是集群,所以两个项目版本分别搞成v1和v2 端口分别是8888和9999
项目1:
FROM centos
MAINTAINER caofeng<caofeng2012@126.com>
LABEL name="Java1234 Jre Image" \
build-date="20200114"
ADD server-jre-8u151-linux-x64.tar.gz /home/
ADD sessionshare2-v1.jar /home/
ENV WORKPATH /home/
WORKDIR $WORKPATH
ENV JAVA_HOME /home/jdk1.8.0_151
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $PATH:$JAVA_HOME/bin
EXPOSE 8888
CMD java -jar /home/sessionshare2-v1.jar
项目2:
FROM centos
MAINTAINER caofeng<caofeng2012@126.com>
LABEL name="Java1234 Jre Image" \
build-date="20200114"
ADD server-jre-8u151-linux-x64.tar.gz /home/
ADD sessionshare2-v2.jar /home/
ENV WORKPATH /home/
WORKDIR $WORKPATH
ENV JAVA_HOME /home/jdk1.8.0_151
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $PATH:$JAVA_HOME/bin
EXPOSE 9999
CMD java -jar /home/sessionshare2-v2.jar
构建镜像
docker build -f myJreDockerFile -t java1234/myjre:1.7 .
docker build -f myJreDockerFile2 -t java1234/myjre:2.1 .
并且启动镜像
docker run -itd -p 8888:8888 eb587d987876
docker run -itd -p 9999:9999 45b7242944ca
浏览器访问测试