Skip to content

Update React / Spring / MySQL example#99

Merged
aiordache merged 4 commits intodocker:masterfrom
frgreiner:master
Mar 22, 2021
Merged

Update React / Spring / MySQL example#99
aiordache merged 4 commits intodocker:masterfrom
frgreiner:master

Conversation

@frgreiner
Copy link
Contributor

I would like to suggest the following improvements:

  • Update README.md title from NodeJS to Spring
  • Always restart spring backend service - when starting this example for the first time using docker-compose up -d the backend container fails to start as the mysql container is up and running but still initializing and not ready to accept connections. The depends_on: ... option doesn't work as expected if the mysql volume isn't initialized yet. By adding restart: always the spring backend will restart until the connection to the database can be established. This leads to a lot of exception stacktraces printed to the container log (only when started the first time), but in my opinion thats better than not starting at all.
  • Also pass db-password secret to spring backend - as the mysql container uses a secret file to set the MYSQL_ROOT_PASSWORD, the spring backend should use the secret file as well, so you can change the password.txt file without making any changes to the backend source files.

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
Copy link
Contributor

@aiordache aiordache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@aiordache
Copy link
Contributor

Could you try adding a DB heathcheck like this:

  db:
    ...
    healthcheck:
      test: "mysqladmin ping -h \"127.0.0.1\" --silent"
      interval: 3s
      retries: 5

and make the backend to wait for the DB to be healthy before connecting to it:

  backend:
  ....
    depends_on:
       db:
         condition: service_healthy

Not sure if this healthcheck is reliable but seemed to work for me.

 - a start_period of 30s + 15s (interval * retries) should be long enough for mysql to initialize

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
@frgreiner
Copy link
Contributor Author

Nice! Thats a smooth way to solve the race condition.
And for the reliability: it seems to be equivalent to the solution used with the oracle mysql-server image.

@aiordache aiordache merged commit a2cf9cc into docker:master Mar 22, 2021
krusher336 pushed a commit to Inteliself/awesome-compose that referenced this pull request Apr 13, 2021
* Update README.md title from NodeJS to Spring

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Always restart spring backend service

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Also pass db-password secret to spring backend

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Add healthcheck to the mysql service

 - a start_period of 30s + 15s (interval * retries) should be long enough for mysql to initialize

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
krusher336 pushed a commit to Inteliself/awesome-compose that referenced this pull request May 2, 2021
* Update README.md title from NodeJS to Spring

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Always restart spring backend service

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Also pass db-password secret to spring backend

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Add healthcheck to the mysql service

 - a start_period of 30s + 15s (interval * retries) should be long enough for mysql to initialize

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
krusher336 pushed a commit to Inteliself/awesome-compose that referenced this pull request May 2, 2021
* Update README.md title from NodeJS to Spring

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Always restart spring backend service

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Also pass db-password secret to spring backend

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Add healthcheck to the mysql service

 - a start_period of 30s + 15s (interval * retries) should be long enough for mysql to initialize

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
krusher336 pushed a commit to Inteliself/awesome-compose that referenced this pull request May 3, 2021
* Update README.md title from NodeJS to Spring

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Always restart spring backend service

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Also pass db-password secret to spring backend

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Add healthcheck to the mysql service

 - a start_period of 30s + 15s (interval * retries) should be long enough for mysql to initialize

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
archii pushed a commit to archii/awesome-compose that referenced this pull request Jul 22, 2021
* Update README.md title from NodeJS to Spring

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Always restart spring backend service

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Also pass db-password secret to spring backend

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>

* Add healthcheck to the mysql service

 - a start_period of 30s + 15s (interval * retries) should be long enough for mysql to initialize

Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants