Container can't connect to MySql DB - mysql

I have one container running MySQL and want to connect to the DB from another container (Wordpress). When running the container locally on my laptop it can connect to the DB running on Bluemix. Running the same container on Bluemix
ice run --name=wordpress1 -p 80 -e WORDPRESS_DB_PASSWORD=xxx -e WORDPRESS_DB_HOST=129.41.234.102:3306 registry-ice.ng.bluemix.net/rhocheck/wordpress:latest
I get this errors:
Warning: mysqli::mysqli(): (HY000/2002): No route to host in - on line 10
The DB is up an running. I can connect even from a container on Bluemix I connected vie ssh
Any ideas?

I would use the ClearDB Service instead. The MySQL service is experimental. ClearDB is an awesome company that does hosted MySQL. Could you try binding CLearDB to your app/container and connect via that way?

Related

How to connect to MySQL database cluster

I tried to install a MySQL cluster with the Docker image below.
mysql/mysql-cluster - Docker Image | Docker Hub
The Docker image is pulled and run successfully.
Despite that I could connect to the cluster in the terminal (as shown in the screen capture below), I don't know how to connect to it with MySQL Workbench or DBeaver.
In your docker run command, you can use -p 3306:3306 (or any available port). Then you can use <host>:<port> from Workbench or Dbeaver connection URL.
I assume that you already know how to add new DB connection to MySQL Workbench or DBeaver. The information that you want is the connection URL and the username/password of an authenticated user that you need to use to connect to your MySQL cluster.
For the connection URL: 192.168.0.10 (no port in your example)
You need to have your MySQL Workbench or DBeaver connect to the URL of the MySQL node, which is mysql1 node in your example. As shown in your screen capture, it is 192.168.0.10 without any explicit port. But if you have troubles with the URL, you can run docker ps to check what host and port that your mysql1 is running and exposed at.
For the username/password: root/tpffnrtm1 (the password is the value of MYSQL_ROOT_PASSWORD as shown in your docker run of MySQL node command)
I assume that you just want to connect the DB cluster by any means (root or non-root privileges is totally fine for you).

Can't connect to MySQL server running inside custom docker

I'm running this on a Ubuntu terminal on my Windows laptop. I'm using docker desktop and have enabled integration with Ubuntu like so:
I've also tried this with docker installed through the Ubuntu terminal (instead of Docker desktop on Windows), but experienced the same issue.
I have a MySQL database in a docker image, and an api docker image, and am running both:
I can access MySQL by running the following command: mysql -uroot -ppassword -h0.0.0.0 -P3306. The api is referencing is connected to this container with the following connection string located in appsettings.json: "Server=0.0.0.0; Port=3306; Uid=root; Pwd=#G3minar31; Database=cybersecuritydatabase". This is also shown in the image below. However, when I try to make a request to the endpoint from the backendapi container (http://127.0.0.1:5001/company/allcompanies), I receive a Can't connect to server error.
How can I resolve this?
UPDATE: When I run mysql -uroot -ppassword -h0.0.0.0 -P3306 in my Windows terminal I receive the following error: ERROR 2003 (HY000): Can't connect to MySQL server on '0.0.0.0:3306' (10049), but if I run mysql -uroot -ppassword -P3306 without specifying the host, MySQL starts successfully.
0.0.0.0 or 127.0.0.1 in config won't work it will point to the app container
either you:
change db address in appsettings.json to your machine local address e.g: 192.168 ..
create a docker network and connect the 2 containers, change db address in appsettings.json to mysql container name instead of an ip address
Run mysql and backendapi with docker-compose, change db address in appsettings.json to mysql service name instead of an ip address, I recommend this

Nextcloud in Docker & MySQL on Host

I'm running docker on my Raspberry Pi. I'm intending to run a few services locally (NextCloud, Bitwarden, etc) and want to use one MariaDB Instance, not one for each as most tutorial show. I've been trying to figure out how to make that work.
I installed mariadb on my RPI and nextcloud via Docker. I passed the MySQL environment variables to that container:
environment:
- MYSQL_PASSWORD=xxx
- MYSQL_DATABASE=dbname
- MYSQL_USER=user
- MYSQL_HOST=192.168.178.36
When I go to the NC initialization page and enter the data, it says Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused".
I addded "user#IP" to MySQL and granted it all access to the DB. The IP is the Docker-internal IP of the Container (172.xxx)

Can't reach MySQL hosted DB from Docker .NET Core

I’ve got a DigitalOcean Droplet that run Ubuntu and I’ve installed MySQL to it. I can reach it from my computer with SSH connection from MySQL workbench, so the remote access is Ok.
The hostname is 127.0.0.1
The bind address in my mysqld.cnf: 127.0.0.1
I’ve got a .NET Core API and I would like to use Docker to run it. I made the container push to docker hub and pulled it to the droplet. When I try to run I get this error:
An error occurred using the connection to database “ on server
‘127.0.0.1’.
My connection string:
"Server=127.0.0.1;Port=3306;Database=db;Uid=user;Pwd=pass”
I tried to server: localhost
IP address for docker0: 172.17.0.1 so I tried this to connectionString as well.
I don’t understand why can I connect to DB from MySQL workbench and cannot from .NET Core Web API.
The .NET Core version is 3.1.
Your .NET Core is inside container. Thus if you try to connect localhost or 127.0.0.1, it will try to connect the container itself, not the host. Since your MySQL is on your host, not inside the container, you can access it with other IP.
For example you have eth0 or enps0 or something like that, then that interface have IP 192.168.1.2, then you can use this IP as connection string.
Or, the alternate way, is using --network host when creating container. In this way, if you use 127.0.0.1, it will try to connect the host.

Cannot connect to AWS RDS again

I am running an AWS RDS. I used to be able to connect to it via MySQL workbench, and my EC2 instance running a laravel application was also connected to it which has been working fine so far but I had an issue with my storage space and needed to download and upload some files on my ec2 instance just to free up some space.
Because I was connecting using as Filezilla I had to use the command sudo usermod -a -G www-data ubuntu to give ubuntu to the group so i can have access to read and write.
The problem is after running this command i noticed I can no longer connect my workbench to the RDS again. Even my laravel application can't access the RDS again.
My Laravel app throws this error
php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
while workbench throws this
Your connection attempt failed for user ....
How can i resolve this?
I had a similar problem, I restarted my BD RDS