I have a Symfony project which I'm running in 3 docker containers:
A PHP-FPM container
A NginX container
A MySQL container
I have another (Laravel) project which is running through the pre-packaged Vagrant Box setup (Homestead).
I'm now trying to connect to the MySQL database (of the Docker setup) from within the Vagrant box of my Laravel project.
What I know for sure:
I can connect to my MySQL database from my host machine through Sequel Pro.
Host: 127.0.0.1
Port: 3306
What I don't know:
Which host / port should I define in my Laravel project in order to successfully connect to the MySQL database from my docker container setup?
If you can connect from your Workstation in should also work from the VM.
Simply use as connection parameter:
IP: Your Workstation IP
Port: 3306
Important: Publish the port of the Container with : -p 3306:3306
Related
I've created a docker container that runs MySQL on it and exposes it on the default port (3306) on a DO droplet (Ubuntu 20).
I tried accessing it on my laptop with the following parameters:
Hostname: (VPS's IP address. I also tried Public Gateway IP)
Connection: Standard (TCP/IP)
Port: 3306
Username: root
Password: (Password I have set while creating the container)
The error message just says "Could not connect to localhost"
Am I missing a step that maybe exposes the container to the internet?
After a couple of hours, I found out that the docker run command has to have -p parameter. -p=3306:3306 in my case.
I have doctrine config:
doctrine:
dbal:
driver:pdo_mysql
url:"mysql://%database_user%:%database_password%#%database_host%:%database_port%/%database_name%"
Where database_user is root, password is root user password (re-checked), host is my server ip address, port is 3306 and name is my db name.
When I use these from workbench I can connect but from running docker container for php and nginx. And this config, I get connection refused.
Do I need somehow to allow connections from localhost? Why is it working from workbench then?
I have two EC2 instances.
vm1 - has mysql server running as a Docker container
vm2 - has mysql client installed.
Now I want to connect from vm2 to the mysql container running in vm1. In vm1, the container is exposed 3306 to the container port 3306
I tried first telnetting the port as:
telnet <ip-of-vm1> 3306
and I get the below error:
Trying 10.128.15.6...
telnet: Unable to connect to remote host: Connection refused
I even allowed the firewall rules to allow all inboud. And mysql container running without any errors.
Can someone help me on this?
I am using vessel to run my Laravel project.
As I understand it basically simply creates a put-together docker image of my laravel project with mysql and everything.
Now since its running in docker, is it possible for me to access the mySQL databases with datagrip or tableplus on my host machine?
You just need to expose a port via docker. If you dont,you will have port 3306 which can be accessed via the local containers but if you bind port 3307:3306 for instance you can connect to mysql locally on 3307
you will need to connect to MySQL server using the docker containers IP that can be found using docker inspect.
This can also help you:
https://towardsdatascience.com/connect-to-mysql-running-in-docker-container-from-a-local-machine-6d996c574e55
I'm working with node, docker, mysql and sequelize and am trying to connect sequelize to mysql container running on docker. It will only connect through port 3306 despite me having changed the "ports" to 3308-3308. When i look up the running containers i get the following for the mysql database:
ticketgo_database_1 docker-entrypoint.sh mysqld Up 3306/tcp,
0.0.0.0:3308->3308/tcp
Which explains why it can only connect to port 3306 but I need to change the connection port from 3306 since that port is busy on my computer. How can i do that?
Mysql container:
database:
image: mysql
environment:
MYSQL_DATABASE: "ticketgo"
MYSQL_ROOT_PASSWORD: "pass"
volumes:
- "./sql:/docker-entrypoint-initdb.d"
ports:
- "3308:3308"
I guess your app is managed by docker-compose as well. There is no need to change which port is MySQL listening in its own container. Leave squelize connecting to databade:3306 and either do not specify port mapping in MySQL docker compose config or specify: 3308:3306 which means that port 3308 on host will be mapped to the 3306 container port. This does not mean that MySQL will listen to the 3308. It will be continuing listening in its container 3306, and a new port 3308 on the host will be mapped to it.
Only specify a port mapping if you need to access MySQL from outside docker-compose services (from another app on your host or a MySQL GUI for example)
In Port section, change second Port to any you want "3308:3309";
Or You can do this in she'll by -p 3309:3308