Spring Boot Application with Docker Compose MySQL Database

When the number of products which are being built around reusable Rest-based services, This situation has been rapidly detected that splitting out the business functions into reusable services is not only effective, but also this contains a risk. Whenever a service is updated, all services which are deployed along with it. There is no guarantee because the services inevitably share code, data and other components.

Thanks to the containerization, codes can be run in complete isolation very efficiently. The combination of these two allows for a product architecture that optimizes for scalability and versioning.

In this article, Spring Boot application is used as a micro service. Source codes can be seen as follows.

BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap
BootStrap

In this yaml file, there are three profiles as can be seen. First profile is mysql in the docker container and spring application in the local environment. To run mysql in docker use the following snippet (To match the variables, if you change the variables in the code you should also change this snippet).

BootStrap

Second profile is the container profile. Before running this container, mysql has to be up and run already. For detailed information about docker compose, visit this docker-compose guide.

The last profile is about openshift mysql. In this part, openshift will be used. For the detailed information about how to use, please refer this guide.

After application.yml file, Dockerfile should be created.

BootStrap

Finally, compile spring project as a maven file and apply docker build process. For specific information about how to build docker image, please visit this docker build guide. Write docker-compose up in the terminal. This command compiles the project on the second profile in the application file.

BootStrap