title: ARG or ENV, which one to use in this case?
body: <p>This could be maybe a trivial question but reading docs for <a href="https://docs.docker.com/engine/reference/builder/#arg" rel="noreferrer">ARG</a> and <a href="https://docs.docker.com/engine/reference/builder/#env" rel="noreferrer">ENV</a> doesn't put things clear to me.</p>
  <p>I am building a PHP-FPM container and I want to give the ability for enable/disable some extensions on user needs.</p>
  <p>Would be great if this could be done in the Dockerfile by adding conditionals and passing flags on the build command perhaps but AFAIK is not supported.</p>
  <p>In my case and my personal approach is to run a small script when container starts, something like the following:</p>
  <pre><code>#!/bin/sh   
  set -e
  
  RESTART=&quot;false&quot;
  
  # This script will be placed in /config/init/ and run when container starts.
  if  [ &quot;$INSTALL_XDEBUG&quot; == &quot;true&quot; ]; then
      printf &quot;\nInstalling Xdebug ...\n&quot;
      yum install -y  php71-php-pecl-xdebug
      RESTART=&quot;true&quot;
  fi
  ...   
  if  [ &quot;$RESTART&quot; == &quot;true&quot; ]; then
      printf &quot;\nRestarting php-fpm ...\n&quot;
      supervisorctl restart php-fpm
  fi
  
  exec &quot;$@&quot;
  </code></pre>
  <p>This is how my <code>Dockerfile</code> looks like:</p>
  <pre><code>FROM reynierpm/centos7-supervisor
  ENV TERM=xterm \
      PATH=&quot;/root/.composer/vendor/bin:${PATH}&quot; \
      INSTALL_COMPOSER=&quot;false&quot; \
      COMPOSER_ALLOW_SUPERUSER=1 \
      COMPOSER_ALLOW_XDEBUG=1 \
      COMPOSER_DISABLE_XDEBUG_WARN=1 \
      COMPOSER_HOME=&quot;/root/.composer&quot; \
      COMPOSER_CACHE_DIR=&quot;/root/.composer/cache&quot; \
      SYMFONY_INSTALLER=&quot;false&quot; \
      SYMFONY_PROJECT=&quot;false&quot; \
      INSTALL_XDEBUG=&quot;false&quot; \
      INSTALL_MONGO=&quot;false&quot; \
      INSTALL_REDIS=&quot;false&quot; \
      INSTALL_HTTP_REQUEST=&quot;false&quot; \
      INSTALL_UPLOAD_PROGRESS=&quot;false&quot; \
      INSTALL_XATTR=&quot;false&quot;
  
  RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
                     https://rpms.remirepo.net/enterprise/remi-release-7.rpm
  RUN yum install -y  \
          yum-utils \
          git \
          zip \
          unzip \
          nano \
          wget \
          php71-php-fpm \
          php71-php-cli \
          php71-php-common \
          php71-php-gd \
          php71-php-intl \
          php71-php-json \
          php71-php-mbstring \
          php71-php-mcrypt \
          php71-php-mysqlnd \
          php71-php-pdo \
          php71-php-pear \
          php71-php-xml \
          php71-pecl-apcu \
          php71-php-pecl-apfd \
          php71-php-pecl-memcache \
          php71-php-pecl-memcached \
          php71-php-pecl-zip &amp;&amp; \
          yum clean all &amp;&amp; rm -rf /tmp/yum*
  
  RUN ln -sfF /opt/remi/php71/enable /etc/profile.d/php71-paths.sh &amp;&amp; \
      ln -sfF /opt/remi/php71/root/usr/bin/{pear,pecl,phar,php,php-cgi,phpize} /usr/local/bin/. &amp;&amp; \
      mv -f /etc/opt/remi/php71/php.ini /etc/php.ini &amp;&amp; \
      ln -s /etc/php.ini /etc/opt/remi/php71/php.ini &amp;&amp; \
      rm -rf /etc/php.d &amp;&amp; \
      mv /etc/opt/remi/php71/php.d /etc/. &amp;&amp; \
      ln -s /etc/php.d /etc/opt/remi/php71/php.d
  
  COPY container-files /
  RUN chmod +x /config/bootstrap.sh
  WORKDIR /data/www
  EXPOSE 9001
  </code></pre>
  <p>Currently this is working but ... If I want to add let's say 20 (a random number) of extensions or any other feature that can be enable|disable then I will end with 20 non necessary <code>ENV</code> (because Dockerfile doesn't support .env files) definition whose only purpose would be set this flag for let the script knows what to do then ...</p>
  <ul>
  <li>Is this the right way to do it?</li>
  <li>Should I use <code>ENV</code> for this purpose?</li>
  </ul>
  <p>I am open to ideas if you have a different approach for achieve this please let me know about it</p>