yoram
yoram

Reputation: 303

How to connect Mysql docker container to Grafana

I run two containers on EC2 instance:

docker run -d --name=grafana -p 3000:3000 grafana/grafana

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

In the Grafana dashboard when I added the host 18.211.211.211:3306

and press test, I got the following error: dial tcp 18.211.211.211:3306: connect: connection refused

Also ran the following commands, without success:

sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp

sudo firewall-cmd --reload

How to solve this, any idea? Thank you

Upvotes: 1

Views: 2819

Answers (2)

Wasim Ansari
Wasim Ansari

Reputation: 290

I got the solution with 2 steps.

  1. Expose port 3306 from your docker to you localhost by adding -p 3306:3306 and also use the version 5.7 of MySQL image.

docker run --name some-mysql -p 443:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d --rm mysql:5.7

  1. When connecting to MySQL from Grafana use IP address of the machine rather then localhost or 0.0.0.0 or 127.0.0.1

Upvotes: 2

Felix Sittenauer
Felix Sittenauer

Reputation: 23

You have to forward the mysql port 3306 with -p 3306:3306. For security reasons and since you are running Grafana on the same host as MySql, I'd suggest you use docker's bridge network and a private IP instead. Unfortunately the -p option will alter your Iptables in a way that it bypasses your firewall config. You should have a look at this guide or the official docker iptable docs.

Upvotes: 1

Related Questions