I am quite new to Docker and I spent 3 days but still no luck on fixing this issue.
In short I am trying to spin up an environment of Magento 1.9 + mySQL + myphpadmin so I can restore my current legacy Magento project onto it.
Here is the image I use - https://hub.docker.com/r/alexcheng/magento
And I try to use docker-compose.yml for setting up the environment.
I keep changing my yml file by referencing different articles but when I connect to localhost for setting up DB connection, I keep getting error = Database connection.
I tried different combinations such as hostname = db or sqldb, port 3306 etc but still no luck.
For each time I respun up the environment, I completely removed the containers and volumes.
Can you please give us the full error message your’re getting?
You may want to change this typo into sqldb instead of slqdb (in many occurences); this is just confusing.
Did you try without hostname: sqldb? Anything that needs to connect to the database from within the same Compose setup can just use the service name you defined in the same file. (Now being slqdb: for you, which you indeed referred to in PMA_HOST: slqdb with the same typo.)
(Also, please use the editing toolbar to format code such as the Compose file, for which whitespace matters. I now fixed the formatting for you.)
Arjan is right: docker-compose creates user defined networks, which provide a dns-based service discovery. Within a user defined network, each container is able to communicate with other containers of the same network using the service name and container port of the application in the target container.
Note: if you want to use db you either need to rename the service to db or switch the networks: declaration to the long syntax (which allows to declare an alias) and add the alias db to the network. After this is done, the alias will be available via service discovery as well.
I see localhost in your screenshot. That should read sqldb to make the Magento container access the MySQL container.
Aside, seeing the following, I wonder why Magento is even asking for it:
Also, when using phpMyAdmin I think the following is wrong too: MA_HOST: pmahost. I’d say, but did not validate, that phpMyAdmin wants to know the host of the database. Which should also refer to sqldb then.