SOLVED - Connecting ha docker to external mysql docker in different host

Hi guys,

I’ve recently got into the home automation and i must say i am impressed with what home assistant has to offer.

I am currently running home assistant on one of my existing docker host just using the official docker images.

Can anyone advise if its possible to connect the docker container tonan external mysql db running on dofferent host.

Ive tried with putting the the connector: component in configuration.xml and got some errors.

There seems to be success running both ha docker and mysql docker on same host but dont want to do that as i have an existing mysql setup.

Appreciate any help. Cheers

The MySQL database just needs to support connecting from outside of localhost. You will need to configure your DB to allow that.

Running on another host doesn’t really have any bearing on whether or not you can use it remotely. At that point it’s just another service on your network

1 Like

Thank you. I’m well aware of that.

My question is more on, is it possible to be configured using the docker container to talk to external mysql server.

If so, how do you do it? What exact settings do you put in configuration.yaml file?

There is nothing special to put into the config. It’s just connecting to another machine on your network. Forget that it’s running in docker, because that is irrelevant. Just put in the IP address of the host running the MySQL docker container. You DID map the container running MySQL to the correct ports on the host, right?

Apologies. Its still not clear. I did mention that the mysql instance is being hosted outside the docker host where ha container is running.

Meaning its seperate to where ha container lives.

There is no issue with mysql on the other host. I have various web applications that talks to it through the normal mysql port fine.

Are you saying when you run docker create you can pass in some options to connect to the mysql server?

Pls adv. Cheers

I thought you were running MySQL inside docker on another docker host. That’s what it sounded like.

Just to be 100% clear, there is literally nothing you need to do to the HA docker container to get it to connect to a MySQL database running on another machine in your network. In docker or otherwise.

There is nothing special in the config aside from telling it the IP address of the MySQL server.

What is your network configuration on your HA docker container? I use net=host on mine

Yes, that’s right.

I use macvlan, so the ha container is being treated just like any other host on the network.

I have multiple VLAN running on my home lab, hence need to do macvlan.

So just to clarify, do you have a ha docker container running on one docker host.
then you also have MySQL instance running on another docker host? and the connection just works… if so. I would love to find out
how you did that.

I don’t understand what the issue is or why you think HA in docker cares where the database is.

Yes, I have had this set up exactly like this. I moved to a postgresql database though, and run it in another docker container on the same host but I don’t link the containers. They are treated as separate devices on the network. Prior to moving to postgresql, my MySQL database was running in a freebsd jail and worked just fine with my HA docker.

I don’t know why yours isn’t working but there is nothing special in the configuration or docker settings that allow it.

Ok so can you explain to me how docker talks to the mysql server located in another docker host?
I

I dont understand why you keep on saying its not required. Then how does it talk to it? How does it know where to connect to? Saw some write up you may be able to do HA docker and mysql docker in the SAME host…

But as i keep on pointing out to you. Its NOT on the same host. This containers are on different host, they are NOT on the same vlan/network.

You can provide how exactly you configured this in your environment.

You stated that you understand that it is merely another machine on your network. You just point it to the IP address of the other Docker host, assuming the other docker host is exposing the ports that your database is running on. I don’t really know why this seems that difficult. The documentation is quite clear on this.

db_url (Optional): The URL which point to your database.

You use the mysql URL form like explained in the documentation…

mysql://user:password@SERVER_IP/DB_NAME

It doesn’t need to be, as I keep saying. As long as you can reach the database from the VLAN/HA host, it doesn’t matter if it’s running in a docker container on your network or someone else’s network (cloud).

Ok ive tried all that last night. It didnt work. I will paste the exact error. I am under the impression you can only do the recorder component under hass.io setup? Is that correct?

I am under the impression you can only do the recorder component under hass.io setup? Is that correct?

No, that is incorrect. I am running this under just a normal Docker instance. The documentation does not state this either. I can connect to my postgresql database and see all the events and actions that my HA is performing.

Nice one. Thats what i want to know… i got the db_url component not found last night and i follow the documentation you mentioned. Will have yto paste the exact error. Juat hard doing this from a phone

Its funny how you only mention this now … and yet you keep on saying there is no extra configuration required in any config? :slight_smile:

My recorder config is exactly this:

recorder:
  purge_interval: 7
  purge_keep_days: 14
  db_url: postgresql://user:[email protected]/hass

Thank you!! Mine is similar

1 Like

What do you mean?

There is no extra configuration. You put in the IP address of your database just like the documentation says. What extra configuration am I doing?

Only diff is changing postgress to mysql on that line

Checkout:

https://community.home-assistant.io/t/setting-up-mysql-on-a-synology-nas-docker-container