I'm currently trying to dockerize my app for local development. For a bit of context, it is using Magento.
I have a configuration file where I'm used to set 127.0.0.1 as MySQL hostname as the web app is running on the same host as MariaDB.
Initially, I've tried to link my container within my docker-compose file using 'links' (below an extract of my docker-compose setting at this point)
mariadb:
image: mariadb:5.5
php-fpm:
build: docker/php-fpm
links:
- "mariadb:mysql"
At this point, MariaDB was reachable by setting mysql as hostname in my configuration file instead of 127.0.0.1. However, I wanted to keep 127.0.0.1.
After a bit of digging, I've found this blog post where it is explained how to set up containers so that it can be reached through localhost or 127.0.0.1
This is working as I'm expecting but it has a flaw.
Without Docker, I'm able to run PHP scripts which leverage magento core modules by loading it. But with Docker and the blog post configuration, I'm not able to do it anymore as Magento is weirdly expecting for a DB hostname called "mysql".
Is there anyway through docker-compose to have a container be reachable with localhost and an hostname?
Without Docker, if I install MariaDB on my host machine, I am able to connect to its instance through 127.0.0.1:3306 or mysql://. I want to get a similar behaviour.