Skip to content
Advertisement

Java.net.ConnectException: Connection refused on Docker + Keycloak

I’m new to Docker and I’m having a hard time connecting Keycloak to my local MySQL database. Does anyone have a hint of what’s going on? This is my Dockerfile:

JavaScript

The error log shows:

JavaScript

Steps already taken:

  • Disabled Firewall;
  • Added bind-address: 0.0.0.0 to my my.cnf file;
  • root@% already has all privileges;
  • Tries setting DB_ADDR and DB_VENDOR in all possible configurations;
  • Server is already started and connection through Workbench runs fine.

Any help would be hugely appreciated!!

Advertisement

Answer

In a multi-stage build, each FROM line completely resets things like ENV settings, so the settings from the first stage aren’t appearing in the final image.

JavaScript

In general, run-time or deploy-time settings like the database location and credentials shouldn’t be compiled into your Dockerfile. (You don’t want to rebuild the image when you deploy it somewhere different, and the credentials can be pretty easily extracted from the built image.) If you’re running this through Docker Compose, you could put these environment-specific settings in your docker-compose.yml file, or use an external environment file:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement