1、在目录下创建Dockerfile
image.png
2、Dockerfile文件内容:
FROM java:8MAINTAINER 457030599@qq.comVOLUME /tmp ARG JAR_FILE COPY guns-rest-0.0.1.jar app.jar RUN bash -c 'touch /app.jar'EXPOSE 80ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","-Denv=DEV","/app.jar"]
3、远程登陆服务器,执行脚本
a、首先在系统设置里面一个远程host
image.png
b、在配置里的Post Step选Execute shell script on remote host using ssh
image.png
4、详细脚本内容
docker stop guns-rest #停掉容器docker rm guns-rest #删除容器\cp /opt/data/jenkins/workspace/my-wechat/guns-rest/target/guns-rest-0.0.1.jar /opt/data/jenkins/workspace/my-wechat/docker/guns-rest-0.0.1.jar #jar包复制到dockerfile相同目录下cd /opt/data/jenkins/workspace/my-wechat/guns-rest/docker docker build -t hsshy/guns-rest . #构建镜像docker run --name guns-rest -p 80:80 -d hsshy/guns-rest #运行容器
作者:yellow_han
链接:https://www.jianshu.com/p/b1825a4ab0a3