title: How to pass variables from .gitlab.ci.yml to Dockerfile
body: <p>How can I pass one variables value from <code>.gitlab-ci.yml</code> to <code>Dockerfile</code>?</p>
  <p>e.g.
  The <em><strong>.gitlab-ci.yml</strong></em> contains:</p>
  <pre><code>variables:
    var1: ex_variable_1
    var2: ex_variable_1
  
  stages:
    - build
  
  build:
    stage: build
    script:
      - sudo docker build . -t ${CI_PROJECT_PATH_SLUG}
                            --build-arg var1
                            --build-arg var2
      - sudo docker run -dit --name ${CI_PROJECT_PATH_SLUG} --cap-add=NET_ADMIN ${CI_PROJECT_PATH_SLUG}:latest
  </code></pre>
  <p>The <em><strong>Dockefile</strong></em> contains:</p>
  <pre><code>FROM centos:6.9
  
  ENV var1 ${var1}
  ENV var2 ${var2}
  
  RUN echo &quot;Print var1 $var1&quot;
  RUN echo &quot;Print var2 $var2
  </code></pre>
  <p>So what I want is to pass <strong>var1</strong> and <strong>var2</strong> from <code>.gitlab-ci.yml</code> to <code>Dockerfile</code>.</p>