Home > Java > javaTutorial > body text

How Springboot uses docker-compose to implement dynamic configuration

WBOY
Release: 2023-05-18 19:55:04
forward
795 people have browsed it

Use docker-compose to achieve dynamic configuration

When packaging Springboot applications, we hope that the configuration in application.property or yml can be modified when the project is started; not when packaging the docker image. The value cannot be modified after it is determined. At this time, this requirement can be achieved through the environment variable function provided by yml;

In the yml file, the value in the system environment variable can be obtained through ${Envirment_variable}; Therefore, you can configure the environment variables in the docker-compose file, so that when the docker image is started, the configuration in the application is defined through the variables specified in docker-compose.

For example

My application integrates cas single sign-on, but the server address of this single sign-on is uncertain

So I can write this in the configuration file

How Springboot uses docker-compose to implement dynamic configuration

The value in cas.server.url here is obtained from the system’s environment variable CAS_SERVER. If the environment variable in the system is not obtained, then use the address https://sophon15:8393 Address;

Configuration in docker-compose

How Springboot uses docker-compose to implement dynamic configuration

That’s it;

By the way, let’s talk about how to configure it in docker-compose The host of the system; sophon15 here is the host address

Just configure it in the extra_hosts attribute of docker-compose

As shown in the figure

How Springboot uses docker-compose to implement dynamic configuration

The above is the detailed content of How Springboot uses docker-compose to implement dynamic configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!