title: Loop/Iterate in Dockerfile
body: <p>I'd like to include and enable some custom plug-ins in an official docker base image of an application.</p>
  
  <p>Here is how directory structure looks like;</p>
  
  <pre><code>.
  +-- Dockerfile
  +-- plugins
  |   +-- plugin_1
  |   +-- plugin_2
  |   +-- plugin_3
  |   +-- ...
  |   +-- plugin_n
  </code></pre>
  
  <p>Dockerfile looks like the following if I need to include plug-ins <em>plugin_1</em>, <em>plugin_3</em>, <em>plugin_7</em> and <em>plugin_8</em>;</p>
  
  <pre><code>FROM myapp_officialimage
  
  COPY plugins/plugin_1/* /usr/lib/myapp/plugins/
  RUN myapp-plugins.sh enable plugin_1
  
  COPY plugins/plugin_3/* /usr/lib/myapp/plugins/
  RUN myapp-plugins.sh enable plugin_3
  
  COPY plugins/plugin_7/* /usr/lib/myapp/plugins/
  RUN myapp-plugins.sh enable plugin_7
  
  COPY plugins/plugin_8/* /usr/lib/myapp/plugins/
  RUN myapp-plugins.sh enable plugin_8
  
  CMD ["myapp-start.sh"]
  </code></pre>
  
  <p><strong>Question is</strong>, is it possible to iterate/loop over a list in order to eliminate boilerplate above?</p>
  
  <p>For example, Dockerfile like below would be cleaner and more maintainable;</p>
  
  <pre><code>FROM myapp_officialimage
  
  ENV CUSTOM_PLUGIN_LIST="plugin_1 plugin_3 plugin_7 plugin_8"
  
  for plugin in $CUSTOM_PLUGIN_LIST; \
  do \
      COPY plugins/$plugin/* /usr/lib/myapp/plugins/ \
      RUN myapp-plugins.sh enable $plugin \
  done
  
  CMD ["myapp-start.sh"]
  </code></pre>