How do I run a spring boot executable jar in a Production environment?

后端 未结 9 2130
一向
一向 2020-12-02 04:19

Spring boot\'s preferred deployment method is via a executable jar file which contains tomcat inside.

It is started with a simple java -jar myapp.jar.

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 05:06

    By far the most easiest and reliable way to run Spring Boot applications in production is with Docker. Use Docker Compose, Docker Swarm or Kubernetes if you need to use multiple connected services.

    Here's a simple Dockerfile from the official Spring Boot Docker guide to get you started:

    FROM frolvlad/alpine-oraclejdk8:slim
    VOLUME /tmp
    ADD YOUR-APP-NAME.jar app.jar
    RUN sh -c 'touch /app.jar'
    ENV JAVA_OPTS=""
    ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
    

    Here's a sample command line to run the container as a daemon:

    docker run \
      -d --restart=always \
      -e "SPRING_PROFILES_ACTIVE=prod" \
      -p 8080:8080 \
      prefix/imagename
    

提交回复
热议问题