I can’t override a Docker variable. How to resolve?

Asked

Viewed 36 times

0

I have this next 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 inciting xdebug.remote_host with the test value 'abcd'.

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

After the container is working, I check the content of php.ini that’s 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 value abcd past dockerfile, but cannot overwrite with value 123456 in the container survey process according to what is suggested in the documentation Overriding Dockerfile image defaults and Additionally, the Operator can set any Environment variable in the container by using one or more -e flags.

1 answer

0

Possibly your command echo is interpreting the value of the REMOTE_HOST variable.

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

After creating the image, php.ini probably looks like this.:
Xdebug.remote_host=abcd

And you want him to stay that way:
Xdebug.remote_host=${REMOTE_HOST}

Try to put the variable inside the single quotes or try to make an escape from the special character "$" variable so that the final result is as in the line above:
echo 'Xdebug.remote_host=${REMOTE_HOST}';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.