Spring Boot testing in docker containers

docker
java

#1

Hi there,

I’m quite new to CircleCI so please excuse me if this question somewhat sounds generic.
I’m creating spring boot applications that communicate with databases on other machines.
For this kind of applications I want to define a pipeline that could look like this:

  1. Code Push to CVS
  2. Build application
  3. Run application tests
  4. Deploy application to remote server

My plan is to spin up two docker containers. One of them contains the application, and the other one contains a mysql db instance for example that the application uses.
So far everything would work great, except for the tests.
I’m simply not able to execute my application tests and use the remote mysql instance for this.

On the other side, It might be better for testing to create a docker container that contains both, the application and the mysql instance on one machine. Then my tests would work as the hostname “localhost” should be familiar for the mysql connection.

But then I would have different docker containers (testing and deployment).

Is there some sort of best practice when working with Spring Boot projects and CircleCI? All I found so far in the internet showed some basic examples that did not include communication to remote machines while testing.


#2

Never mind, I got this to work.
Turned out that port 3306 is being used by the host machine.
So I simply mapped the mysql port to another port:

docker run … -p 3307:3306 …

Maybe this helps someone.


#3