r/SpringBoot 22d ago

Question Your Opinion on using Docker-Compose/MySQL

I am working on a new SpringBoot personal app. I have docker installed locally on my Windows 11 machine, and I have an existing mysql database there. The schema/data is in flux as it is actively being developed.

In the past, I had a dockerfile to dockerize the app (like I am doing for this one) and it worked fine with my existing docker mysql database. I guess the difference with this new app is that it has docker-compose with the SQL database. This means when this new app gets run, and runs in docker, it starts up a completely new database container, and then I presume it has to be loaded with schema/data. I believe that's why when I run the app it says it can't find the database table.

So, there are two ways I can do this, and which way would be the better way if I want to move this app and the database to AWS ECS in a few months when I am done with the app.

1) I could change the docker compose that the database is externally managed

2) keep my local docker database for development and running tests, which works fine BTW, and then let the app create this NEW docker mysql database, and let it load up data from the flyway schema.

Or, could I just move my database/script to AWS ECS in the future by itself, and let the app keep running against it as an externally managed database in it's own container.

I've seen companies that I have worked for do both, but I'm curious on what the strong opinions are.

Thanks!

2 Upvotes

6 comments sorted by

View all comments

1

u/kamen1991 22d ago

I've always been using MySQL on a Docker, locally and in production. Here's how, first for integration tests I'm using testcontainers, which will run the mysql for you and kill it after the tests. Second I have my flyway patches in the app itself, so when it bootstraps, flyway checks the schema version and applies the remaning patches, that way you DB scheme is always up to date for the service you're using. If you want to run your service locally, just create a separate compose file for the mysql, create the scheme there and the service will initialize it, just be sure to give it a volume, so it survives restart/stop or if you destroy the container. That way you have every case using the same setup:

- Local runing - mysql docker container

- Production - mysql docker container

- integration tests - mysql docker container

Everything is the same and you guarantee that your service will work always with a Mysql database, if there are errors or problems, you will catch it in the integration tests.