Home >Java >javaTutorial >How Springboot uses docker-compose to implement 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.
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
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
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
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!