Home >Java >javaTutorial >How Springboot uses docker-compose to implement dynamic configuration

How Springboot uses docker-compose to implement dynamic configuration

WBOY
WBOYforward
2023-05-18 19:55:04850browse

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete