Connect to local MySQL DB after launching Metabase with Docker

Hi All,

I've endlessly searched the forum here, stackoverflow and the deep dark web but I still can't wrap my head around this.

Problem
After running Metabase with Docker I am trying to add a local MySQL DB but get the following error:
Could not connect to address=(host=127.0.0.1)(port=3306)(type=master) : Socket fail to connect to host:127.0.0.1, port:3306. Connection refused (Connection refused)

My Info
Metabase version 0.39.0.1
MySQL v8.0.24
I am hosting this DB on my machine and am able to connect to it via Workbench

Extra Info
I've also been able to connect to this DB when launching Metabase from the JAR file via
java -jar metabase.jar

Thanks in advance!
Dimitri

Hi @lpgroup
Because Docker containers are like a separate server, so 127.0.0.1 is the localhost of the container.
https://stackoverflow.com/questions/28056522/access-host-database-from-a-docker-container

Hi @flamber, thanks for the response and link share. I'm still new to docker so please bare with me.

From what I understand, we need to add the host (my localhost; 127.0.0.1)? into the container running the metabase instance?

The stackoverflow example adds a static IP to a host name docker
docker run --add-host=docker:10.180.0.1 --rm -it debian

How do I do this? Do I append it to the following docker run command?
docker run -d -p 3000:3000 --name metabase metabase/metabase

Thanks

@lpgroup No, if you want to connect from a container to the host, then you'll use this address from within the container: host.docker.internal instead of localhost, which refers to the container itself.

To put it in other words: A Docker container is very similar to have a separate server. So if you want that "server" to connect to something else in your network, then you need to use the right addresses and make sure everything is "connected" correctly.

I would very much recommend that you don't use Docker - it's a very big technical project by itself.

If you still want to use Docker, then I would recommend that you have a look in some Docker forums, since all questions regarding containers and networking is much better answered there.
https://docs.docker.com/
But the Metabase specific parts are mostly listed in the documentation, which I would recommend that you read - after learning about Docker:
https://www.metabase.com/docs/latest/operations-guide/running-metabase-on-docker.html

2 Likes

I agree. For what I need to build, I'm probably over complicating it with Docker.

Thanks for the links. Will check them out when I get serious about doubling down on it.