Docker Community Forums

Share and learn in the Docker community.

Help connection containers

(Smaction) #1


I have gotten some help on the irc channel but as yet no solution. I am having trouble connecting a php-apache container to a mysql container. The frustrating part is that I got it all working and then I brought down and brought back up the containers and it stopped working. I can attach to the mysql contianer and run mysql commands locally but trying to do it from the php-apache container times out. Specifically (HY000/2002): Connection timed out. I can ping the mysql container from the host OS. My docker-compose.yml and Dockerfile are here . The images are both the official PHP an Mysql images. My host OS is Ubuntu 18.04.


(Sam) #2

what address is the php app using to connect to the mysql container? localhost? (careful, localhost means ‘here’, from wherever it is used… inside a container, means inside the container NOT the ‘host’ the container is running on…

also, check to make sure that the mysql server is accepting connections from OUTSIDE its container, usually by default is also uses localhost (which would be INSIDE the mysql container ONLY)…

change it to (anywhere) (in mysql.cnf) and restart the container…