docker-compose file to run REST Spring-boot application container and MySQL container

Romil Jain
2 min readDec 4, 2017

--

Refer Part-2 If you want to learn how to dockerize REST Spring-boot application with Hibernate having database as MySQL. This is in continuation of Part-2 so I would recommend to go through that first.

docker-compose

Now, Before we jump in to creating a docker-compose file, Lets build a docker image with Gradle. It will be helpful when we will play around with docker-compose file.

To create a docker image via Gradle, you have to add Docker dependency and plugin in the build.gradle as show below.

If you run below from the project root directory where build.gradle is

$ gradle build buildDocker

you will see docker image created with name ‘gradle-springboot’. Now instead of executing two docker run command to up MYSQL container and gradle-springboot application container, we will create docker-compose file which will do both for us.

So Let’s create a docker-compose file in the project directory as below.

Once you have created docker-compose file, Its time to run it. Run below from the project directory where docker-compose.yml file is

$ docker-compose up

and see how it will create two containers and link both the containers as well.

host file of gradle-springboot application

If you observe there is an entry of ‘172.18.0.3 93bd2fbc2145’ which is nothing but MySQL container.

So, This is how docker-compose helps in executing tasks. One can implement complex applications and create docker-compose to run multiple containers as per the dependency and requirement.

This is end of Part-3 and a simple way to dockerize an application using docker-compose file. Download complete code from here. Refer Part-1 and Part-2 for docker setup and dockerize a spring-boot application with MySQL DB.

--

--

No responses yet