Springboot Docker start parameter delivery

Source: Internet
Author: User

These days a netizen asked, how to use Docker to pass spring.profiles.active=test, that is to say springboot switch configuration file. In the past, when we started the jar directly through Java, we directly followed the--spring.profiles.active=test or the JVM parameter-dspring.profiles.active=test to pass. Let me write some orders.

Non-docker springboot switch profile

Java-jar Test.jar--spring.profiles.active=test #第一种情况切换配置文件

Java-dspring.profiles.active=test-jar Test.jar #第二种情况切换配置文件

Some friends will wonder, through the JVM parameters how can switch it, in fact, Springboot is supported OH.

Docker under springboot switch configuration file

Docker encapsulates the springboot after the switch will be more steps, in fact, it is not difficult. I find a lot of articles on the Internet, and did not see through com.spotify:docker-maven-plugin this Docker packaging plug-in implementation of the environment variables passed parameters, it may be too simple, no one to write, but I see a lot of people need, I still write about it. However, there is an env variable passed through Dockerfile implemented on-line. Below I post the package plugin code in the POM:

Note the changes in ENV nodes and entrypoint

Com.spotifydocker-maven-plugin0.4.11pumelo/${project.artifactid}-${version}frolvlad/alpine-oraclejdk8:slim "" [" SH ","-C "," Java $JAVA _opts-jar/${project.build.finalname}.jar "]/${project.build.directory}${ Project.build.finalname}.jar

Test

After the image is newly packaged, run

Docker run-e java_opts= '-xms128m-xmx256m-dspring.profiles.active=prod '-it pumelo/test-1.0.0/bin/bash

This allows you to switch the Springboot configuration file through the JVM parameters.

Thank you for your crossing.

Springboot Docker start parameter delivery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.