Cannot get Mariadb in seperate container working

I know there are a lot of topics about Mariadb and I have read a lot of them. I cannot get this working, so I am looking for some help.

I have a NUC running ubuntu desktop. On Ubuntu I have a container running Hassio. In a separate container (on the same NUC) I have Influxdb and Grafana. All are working nice!

Now I want to install a third container (On the same NUC) with Mariadb for the recorder and history component. And I cannot get this working.

I can see that the database ‘home assistent’ excists in the container I created with the Mariadb template in Portainer.

MariaDB [(none)]> SHOW DATABASES;

| Database                    |
| homeassistent            |
| information_schema   |
| mysql                          |
| performance_schema |

In the configuration.yaml I have this line:

   db_url: mysql://root:<my password>@

The ip adress and portnumber are from the container, which are visible in Portainer. I also tried the ipadress from the NUC and localhost, but this didn’t work either.

This is the error in the log:

Error during connection setup: (MySQLdb._exceptions.OperationalError) (2002, “Can’t connect to local MySQL server through socket ‘/run/mysqld/mysqld.sock’ (2)”)
(Background on this error at: (retrying in 3 seconds)

Some help is appreciated! Thanks.

you may need to link the containers. Here is an extract of my home assistant docker-compose.
Pay special attention to the depends_on line

      container_name: ha
      image: homeassistant/home-assistant:0.97.2
        - /home/cctv/docker_ha:/config
        - /etc/localtime:/etc/localtime:ro
        - /home/cctv/docker_ha/shell_scripts:/shell_scripts:ro
        - /dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1XETWB5-if00-port0:/dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1XETWB5-if00-port0
        - influxdb
        - zigbee2mqtt
      restart: always
      network_mode: host

Then you may need to use the container name instead of its IP address.
I’ve done something similar for wordpress and mysql DB containers. I’m not home so can’t check exctly how I did it but pretty sure I used the mysql container name instead of its IP address in the wordpress config…

Which can change at any time. Never use the internal IP addresses of the docker containers.