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.

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= : Socket fail to connect to host:, port:3306. Connection refused (Connection refused)

My Info
Metabase version
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!

Hi @lpgroup
Because Docker containers are like a separate server, so is the localhost of the 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; into the container running the metabase instance?

The stackoverflow example adds a static IP to a host name docker
docker run --add-host=docker: --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


@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.
But the Metabase specific parts are mostly listed in the documentation, which I would recommend that you read - after learning about Docker:

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.