1、上传jar包
2、新建 Dockerfile 文件
添加jar包及修改端口
vim Dockerfile
# 基础镜像
FROM java:8
# 添加jar包
ADD service-xxx-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=GMT+8","-jar","-jar","/app.jar"]
# 设置端口
EXPOSE 7004
3、新建 run.sh 脚本(创建并运行)
更改 service-xxx 为 对应 容器名称。
启动命令:sh run.sh
vim run.sh
#!/bin/sh
cur_dir=$(cd `dirname $0`; pwd)
ip=$1
export ip
cd ${cur_dir}
docker build -t service-xxx .
cd ${cur_dir}
echo "启动service-xxx容器"
docker run -itd \
--net host \
--name service-xxx \
-v ${cur_dir}/log:/service-xxx \
--restart always service-xxx
docker exec -ti service-xxx ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
4、新建 update.sh 脚本(更新)
更改 service-xxx 为 对应 容器名称。
启动命令:sh update.sh
vim update.sh
#!/bin/sh
basedir=$(cd `dirname $0`; pwd)
docker cp ${basedir}/service-xxx-0.0.1-SNAPSHOT.jar service-xxx:/app.jar
echo "cp service-xxx-0.0.1-SNAPSHOT.jar success"
docker restart service-xxx
echo "restart service-xxx docker success"