Hello im just new to keycloak. I’ve bee trying to setup keycloak with docker and with external db. Documentation says i had to setup the env vars to make it work. I tried doing it but it seems that keycloak cannot connect to my db. I know theres an instruction to use docker network and use that but my db is not in a docker container. Everytime i run there’s an error of cannot connect to database. How do i go around this?
Im using mysql and using this env vars to run keycloak
DB_VENDOR=mysql
DB_ADDR=127.0.0.1
DB_PORT=3306
DB_DATABASE=keycloak_db
DB_USER=root
DB_PASSWORD=password
Thanks i think i know the problem now.
Docker container cannot connect to my host localhost right away, thats why its not working. And that’s why most of the examples are mysql docker container.
Unless you use network_mode: host, then 127.0.0.1 is localhost inside the container, not the host. You can use DB_ADDR=the proper IP, or maybe 172.17.0.1 instead.
Greetings, I’m trying to do something similar. Ultimately I want to deploy onto an EC2 instance and point to an RDS postgres instance. THat’s a later discussion though. Right now, I’m just tryint to play around with the environmental variables to connect to my docker container host’s local installation of postgres. I’m not including a postgres section in my docker compose file as my production enviroment will be using RDS.
While testing locally on my machine, I am unable to get a good database connection. My docker-compose.yml looks like this:
I keep getting a failure to connect to database error.
I’m not sure if I’m running into an issue with docker on the DB_ADDR variable. Can’t I use 172.17.0.1 to access the host machine’s loopback?loopback
Any idea how I can use these environmental variables to hit a local PG instance?
letting your docker container connect to your localhost is a pain in the a**. I had the same thoughts with you to try stuff before deploying it some server. What i did is i tried to setup a Database on another machine instead and connect to that db via machine’s IP.
Thanks for the info. 172.17.0.1 didn’t work for me and I tried the host IP and that didn’t work either. I’m not sure what to try next. I’ve not seen any examples on the internet on how to use all of the environment variables to connect to a non dockerized database. Thanks for the suggestions.
Tyler
I would check firstly that your host is 172.17.0.1, and not some other address, and secondly that your Postgres server is actualling listening on that address (use “netstat -anp” to list all ports and their processes). Some servers only listen on loopback (127.0.0.0/8) by default, and need to be reconfigured to listen on other interfaces.