I can't overwrite a docker variable. How to solve?



  • 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 one observes, I am inciating the xdebug.remote_host with the test value Abcd..

    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 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, the xdebug.remote_host is being initialized with the value abcd past the dockerfile, but I can't overwrite with the value 1234 past in the container lifting process according to what is suggested in the documentation https://docs.docker.com/engine/reference/run/#overriding-dockerfile-image-defaults and https://docs.docker.com/engine/reference/run/#env-environment-variables



  • Perhaps your command echo be interpreting the value of the REMOTE_HOST variable.

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

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

    And you want him to look like this:
    xdebug.remote_host=${REMOTE_HOST}

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




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2