I have the following piece of definition in a Dockerfile
:
# This aims to be the default value if -e is not present on the run command
ENV HOST_IP=127.0.0.1
...
# Copy the zz-php.ini on the container where it should be
COPY /container-files/etc/php.d/zz-php.ini /etc/php5/mods-available/zz-php.ini
# Create a symlink (same as other .ini files for PHP in Ubuntu)
RUN ln -s /etc/php5/mods-available/zz-php.ini /etc/php5/apache2/conf.d/zz-php.ini
# Copy the script for change the xdebug.remote_host value based on HOST_IP
COPY /container-files/init-scripts/setup_xdebug_ip.sh /usr/local/bin/setup_xdebug_ip.sh
# Execute the script
RUN chmod +x /usr/local/bin/setup_xdebug_ip.sh
This is the relevant piece of definition at zz-php.ini
:
; Xdebug
[Xdebug]
xdebug.remote_enable=true
xdebug.remote_host="192.168.3.1" => this should be overwrited by HOST_IP
xdebug.remote_port="9001"
xdebug.idekey="XDEBUG_PHPSTORM"
This is the content of the script setup_xdebug_ip.sh
:
#!/usr/bin/bash
sed -i -E "s/xdebug.remote_host.*/xdebug.remote_host=$HOST_IP/" /etc/php5/apache2/conf.d/zz-php.ini
In order to build the image and run the container I follow this steps:
-
Build the image:
docker build -t reynierpm/dev-php55 .
-
Run the container:
docker run -e HOST_IP=$(hostname -I | cut -d' ' -f1) --name dev-php5 -it /bin/bash reynierpm/dev-php55
After the image gets built and the container is running I open a browser and point to: http://container_address/index.php
(which contains phpinfo()
) and I can see the value of xdebug.remote_host
as 192.168.3.1
…
why? What is not running when the container start? Why the value doesn’t get overwritten using the provided value by -e
on the run
command?