Env variables in static xml files
I just started to use Docker and I find it’s wonderful. I tried to build a 2 containers environment for Magento, first container for apache and second for mysql. I linked the two containers together and I installed Magento on the apache container, using as DB Host the Mysql container. I obtained the ip of the linked mysql container from the env variable typing “env” on the apache container. It works fine, but the problem is that Magento saves the ip of the mysql server in the local.xml file. If I rebuild the mysql container it obtains a new ip address and magento stops to work until I update the local.xml file. Working on a php setting file (i.e. in wordpress) i can use the function
getenv("MYSQL_PORT_3306_TCP_ADDR") to dynamically obtain the correct ip address, but what can I do if it’s saved in a static file xml file like in Magento?
One Solution collect form web for “Env variables in static xml files”
I found it! When a container is linked to another through –link option, docker automatically add an entry in the container /etc/hosts, with the alias and the ip address of the just linked container!
172.17.0.2 mysql 9e37a5c0a444 my-mysql
I have only to substitute the IP address of the mysql server with the hostname (mysql or my-mysql) and it works also when the IP address is changing