docker(10) : springboot项目构建成镜像[2]

1.创建目录并把jar包放进该目录

2.创建Dockerfile文件

cat > Dockerfile << 'EOF'

FROM openjdk:8-jdk

ADD ./*.jar /app.jar

RUN ln -sf /usr/share/zoneinfo/Asia/ShangHai /etc/localtime \
   && echo Asia/Shanghai > /etc/timezone \
   && dpkg-reconfigure -f noninteractive tzdata

ENTRYPOINT ["java", "-jar", "/app.jar"]
EOF

3.构建镜像

cat > build.sh <<'EOF'
image_name=test
version=0.1
 
 
echo "===========构建==========="
 
docker build -t ${image_name}:${version}  .
EOF

一键构建镜像并启动

cat > install.sh << 'EOF'
 
#!/bin/bash
 
# 全局参数
container_name=test
image_name=test
logfile_path=logs
version=0.1
server_port=8001
active=test
 
 
echo "=====删除之前的镜像和容器====="
docker stop ${container_name}
docker rm ${container_name}
docker rmi ${image_name}:${version}
 
echo "===========构建==========="
 
docker build -t ${image_name}:${version}  .
 
echo "===========运行==========="
docker run -d -p ${server_port}:${server_port} --name=${container_name} \
              --restart=always \
              -v /home/log:/${logfile_path} \
              ${image_name}:${version} \
              --server.port=${server_port} \
              --spring.profiles.active=${active} \
              --logging.path=${logfile_path} 
EOF

你可能感兴趣的:(docker,#,springboot,java制作镜像)