I'm facing a issue and I will appreciate you someone can help me.
I cannot connect to mysql proxy from my docker container.
GCP Enviroment
I have a GCP VM unix with docker installed.
This VM has already the Google Could Sql Proxy configured, and accessible through mysql -u USER -p --host=127.0.0.1 --port=5435
I have a docker container with Ubuntu
Problem
The problem is, inside my container, if I run mysql -u USER -p --host=host.docker.internal --port=5435 or mysql -u USER -p --host=172.17.0.1 --port=5435 I connect access
I cannot connect to mysql. I don't know what I'm missing or doing wrongly.
Thank you!
Related
I am creating very simple database like
mysql -u root -e "CREATE DATABASE IF NOT EXISTS example"
and I want to access it in the doker container like
"mysql://root#localhost/example"
both host and conteiner is ubuntu machine
I suppose answer is very simple but I got lost - Thanks !
With docker, all the stuff can be accessible with localhost. But you need to expose the service to a local port.
So with -p 80:80 in your run command, you will be able to expose the port 80 on your container, to your local port 80.
Docker run doc
I hope it will help you!
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
I have created a MySQL deployment in kubernetes and exposed it as nodes-port.
What I can do:
Access it from inside the cluster using
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -ppassword
What I want to do:
Access the MySQL server from outside the cluster(like accessing a normal MySQL server).
Kubernetes v1.13 in DigitalOcean Cloud.
Guide me, please.
You can access it by mysql -u {username} -p {password} -h {any kubernetes worker ip} -P {nodePort}. After you start mysql container and expose it ad node port through a service.
You need to specify the MYSQL_ROOT_PASSWORD while bringing up the pod. How were you able to bring it up in Docker without it?
I feel like this should be an easy fix but I can't seem to figure this out. I just installed docker and ran:
docker run -d --name test-mysql -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=test mysql
I did this to create my first container. After that I opened sequel pro an typed in the correct things to connect to the database. I got this...
Unable to connect to host 127.0.0.1, or the request timed out.
Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).
MySQL said: Host '172.17.0.1' is not allowed to connect to this MySQL server
Does anyone know how to fix this?
First I run mysql image:
docker run -e MYSQL_ROOT_PASSWORD=password -d -p 127.0.0.1:3308:3306 mysql
Then I use container bash:
docker exec -it my_container_name bash
In Bash I can successfully connect to MySQL server via command:
mysql -uroot -ppassword
But when I try to connect to MySQL container from Windows cmd:
mysql -uroot -ppassword -h127.0.0.1 -P3308
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (10061)
If I connect to 192.168.99.100 instead (this ip is returned by docker-machine ip), then the result is the same.
The question is: How do I correctly expose my MySQL port inside Docker to outside Windows?
The error is in your port mapping in the original docker run command, you just need to provide the ports, not the IP address:
docker run -e MYSQL_ROOT_PASSWORD=password -d -p 3308:3306 mysql
You can run docker ps -a to check for the port mapping in the running containers.
You should now be able to connect to MySQL using
mysql -uroot -ppassword -h192.168.99.100 -P3308
First, check netstat -an to make sure the port is open in Windows. If it is, also check the Windows firewall to make sure nothing is blocking connections to the port.
Most of my Docker experience is in CoreOS, so I'm not exactly sure how Windows handles routing traffic into the container. In CoreOS, it uses a proxy. If there is a proxy in Windows, make sure nothing is interfering with it.
Changing the port in which I was running the image worked.
I checked if this port was used by something else, but it was not used. so I just -desperately- run a new container in a different port '3309'. and it worked fine!
Make sure you have entered the port with -P.