docker-compose deploys springboot jar

1. Run the jar directly

  1. Create yml build file
version: '3.1'

services:
  tulan-system:
    image: openjdk:8u342-jre
    container_name: tulan-system
    command: java -Duser.timezone=Asia/Shanghai -jar /data/xxxx.jar
    restart: always
    network_mode: host # 设置网络模式为host模式
    privileged: true # 设置容器权限为root
    volumes:
      - ./data:/data
      - ./logs:/logs

  1. Upload the jar package that needs to be built to the data directory in the same directory as the yml
  2. Execute the following startup command to start the container
docker-compose -f xxx.yml up -d

2. First build the jar into a mirror and then run the container through the mirror.

  1. Create a Dockerfile image build file
# 基础镜像
FROM  openjdk:8-jre
# author
MAINTAINER 18334723118@163.com
# 设置默认时区
ENV TZ=Asia/Shanghai
# 挂载目录
VOLUME /home/tulan
# 创建目录
RUN mkdir -p /home/tulan
# 指定路径
WORKDIR /home/tulan
# 复制jar文件到路径
COPY tulan-system.jar /home/tulan/tulan-system.jar
# 启动系统服务
ENTRYPOINT ["java","-jar","tulan-system.jar"]

  1. Upload the jar to the same directory as the Dockerfile
  2. Create build yml file
version : '3.8'
services:
  tulan-system:
    container_name: tulan-system
    image: tulan-system
    build:
     #context: ./tulan/modules/system
      context: ./build-env
      dockerfile: Dockerfile_system
    volumes:
      - /home:/home
      - /home/tulan/logs:/home/tulan/logs  
    network_mode: host # 设置网络模式为host模式
    privileged: true # 设置容器权限为root
    logging:
      driver: "json-file"
      options:
        max-size: "500m"
        max-file: "3"
  1. Execute startup command
docker-compose -f xxx.yml up -d

おすすめ

転載: blog.csdn.net/yangfenggh/article/details/131191735