准备docker环境
- centos 7
- jdk1.8
既然是发布springboot jar所以无需使用额外的tomcat(内置)。
CENTOS7 AND JDK1.8
-
docker search centos
-
docker pull centos
-
在下载的centos image中加入jdk1.8,可以直接在dockerfile中下载以及安装,但是我建议还是自己下载对应的jdk之后在本地加载安装,因为在dockerfile中下载时间长,无法查看其进度,容易造成以为安装不成功,其实是jdk源地址无法下载导致。
在同一目录下新增Dockerfile,和需要安装的文件jdk
# Include centos7 and jdk 1.8_191
FROM centos
MAINTAINER xxxxx(xxxxxx@qq.com)
ADD jdk-8u191-linux-x64.tar.gz /usr/local/jdk8
ENV JAVA_HOME /usr/local/jdk8/jdk1.8.0_191
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH :$JAVA_HOME/lib:$JRE_HOME/lib
ENV PATH $PATH:$JAVA_HOME/bin
CMD ["java", "-version"]
-
docker build -t centos-jdk8:v1 .
构建jar包微服务
- 新增Dockerfile(CMD命令可以在docker run的时候替换,所以定义模板时可以随意定义,启动参数也可以定义成ENV,通过docker run的时候传递)
# Include centos, mysql5.7 and java1.8_191 docker images
FROM centos-jdk8:v1
# creater
MAINTAINER (xxx.xx)xxxx@qq.com
ADD deploy_jar /usr/local
# EXPOSE
EXPOSE 5555
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Xmx512m","-Xms512m"
,"-XX:SurvivorRatio=6", "-Xss256k","-XX:+UseConcMarkSweepGC","-jar"]
CMD ["/usr/local/app.jar"]
-
准备发布jar包
-
docker build
-
docker run
docker run -d --name docker-demo-190107 -v /usr/local/log/:/var/log/ -p3308:5555
docker-demo:v1 /usr/local/docker-demo.jar
-
访问测试