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 /container-files/etc/php.d/zz-php.ini /etc/php5/mods-available/zz-php.ini
RUN ln -s /etc/php5/mods-available/zz-php.ini /etc/php5/apache2/conf.d/zz-php.ini
COPY /container-files/init-scripts/setup_xdebug_ip.sh /usr/local/bin/setup_xdebug_ip.sh
RUN chmod +x /usr/local/bin/setup_xdebug_ip.sh
CMD ["/usr/local/bin/setup_xdebug_ip.sh", "/usr/local/bin/setup_php_settings.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

```

**Updated the script**

I have updated the script to see it that's the reason why the value isn't changed and still not working. See the code below:

```
#!/usr/bin/bash

sed -ri "s/^xdebug.remote_host\s*=.*$//g" /etc/php5/apache2/conf.d/zz-php.ini
echo "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?

**UPDATE:**

I've notice that I am only copying the file and setting up the permissions but I am not running it at all:

```
# 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

```

Could this be the issue? Everything that I put under `/usr/local/bin` is executed at container start? If not that's definitively the issue or at least I think.

**UPDATE #2:**

After the suggestions from **@charles-dufly** I've fixed a few things but still not working.

Now the Dockerfile looks like:

```
# This aims to be the default value if -e is not present on the run command
ENV HOST_IP=127.0.0.1
...
ADD container-files /
RUN chmod +x /usr/local/bin/setup_xdebug_ip && \
/usr/local/bin/setup_xdebug_ip && \
chmod +x /usr/local/bin/setup_php_settings && \
ln -s /etc/php5/mods-available/zz-php.ini /etc/php5/apache2/conf.d/zz-php.ini && \
ln -s /etc/php5/mods-available/zz-php-directories.ini /etc/php5/apache2/conf.d/zz-php-directories.ini && \
a2enmod rewrite

EXPOSE 80 9001

CMD ["/usr/local/bin/setup_php_settings"]

```

After build the image I am running the following command:

```
$ docker run -e HOST_IP=192.168.3.120 -p 80:80 --name php55-img-6 -it reynierpm/php5-dev-4 /bin/bash

```

I can see the value of `xdebug.remote_host` being set as `127.0.0.1` but is not taking the value passed as `-e` on the `run` command, why?