I can not overwrite a variable in docker. How to solve?

0

I have this following dockerfile:

...

ENV REMOTE_HOST abcd
RUN figlet SETTING__XDEBUG__php.ini
RUN { \
        echo '[xdebug]'; \
        echo 'zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so'; \
        echo 'xdebug.remote_enable=1'; \
        echo 'xdebug.remote_port=9000'; \  
        echo 'xdebug.remote_autostart=1'; \
        echo 'xdebug.remote_handler=dbgp'; \
        echo 'xdebug.idekey=dockerdebug'; \
        echo 'xdebug.profiler_output_dir="/var/www/html"'; \
        echo 'xdebug.remote_connect_back=0'; \
        echo 'xdebug.remote_host='${REMOTE_HOST}; \
    } >> /usr/local/etc/php/php.ini

...

As you can see, I'm starting the xdebug.remote_host with the test 'abcd' value.

I raise the container with the following command docker run -e "REMOTE_HOST=123456" ...

After the container is working, I check the contents of php.ini this is what I have:

[xdebug]
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp
xdebug.idekey=dockerdebug
xdebug.profiler_output_dir="/var/www/html"
xdebug.remote_connect_back=0
xdebug.remote_host=abcd

That is, xdebug.remote_host is being initialized with the abcd value passed in dockerfile, but I can not overwrite it with 123456 value passed in the container pickup process as suggested in the Overriding Dockerfile image defaults and Additionally, the operator can set any environment variable in the container by using one or more -e flags.

    
asked by anonymous 01.12.2017 / 19:52

1 answer

0

Possibly your echo command interprets the value of the REMOTE_HOST variable.

echo 'xdebug.remote_host =' $ {REMOTE_HOST};

After creating the image, probably the php.ini should look like this: xdebug.remote_host = abcd

And you're wanting it to look like this: xdebug.remote_host = $ {REMOTE_HOST}

Try to put the variable inside the single quotation marks or try to escape the special "$" character of the variable so that the final result is as in the line above: xdebug.remote_host = $ {REMOTE_HOST} ';

    
01.12.2017 / 22:36