title: docker - pass arguments to the script during build
body: <p>I would like to pass argument (from the docker command) to the shell script inside the Dockerfile. </p>
  
  <p>This is the docker command line.</p>
  
  <pre><code>docker build --file=DockerfileTest --build-arg docker_image=PX-release-migration  --tag=test-image:latest --rm=true  .
  </code></pre>
  
  <p>This is a script that is called inside the Dockerfile.</p>
  
  <pre><code>#!/bin/sh -e
  image_name=$1
  echo "docker image is $image_name"
  
  if [[ ($image_name == '') || ($image_name == *"-dev-"*) ]]; then
      echo "This is development"
      cp src/main/resources/application-dev.properties src/main/resources/application.properties
  elif [[ $image_name == *"-preprod-"* ]]; then
      echo "This is preprod"
      cp src/main/resources/application-stg.properties src/main/resources/application.properties
  elif [[ $image_name == *"-release-"* ]]; then
      echo "This is production"
      cp src/main/resources/application-prod.properties src/main/resources/application.properties
  fi
  </code></pre>
  
  <p>When I execute separately the script, it works, but it doe</p>
  
  <p>This is docker file.</p>
  
  <pre><code>ARG spring_env=local
  ARG docker_image=-local-
  
  FROM maven:3.6.1-jdk-8
  COPY . /apps/demo
  
  WORKDIR /apps/demo
  
  RUN chmod +x /apps/demo/initialize_env.sh
  RUN ./initialize_env.sh $docker_image
  
  RUN echo "spring_env is ${spring_env}"
  </code></pre>
  
  <p>So basically, i would like to use a different spring application properties file during the build depending on the docker_image name. If a docker image name contains 'release', i would like to package application-prod.properties during the build. </p>
  
  <p>This is the error message that I am getting. </p>
  
  <pre><code>Step 1/8 : ARG spring_env=local
  Step 2/8 : ARG docker_image=-local-
  Step 3/8 : FROM maven:3.6.1-jdk-8
   ---&gt; 4c81be38db66
  Step 4/8 : COPY . /apps/demo
   ---&gt; 41439197c465
  Step 5/8 : WORKDIR /apps/demo
   ---&gt; Running in 56bd408c2eb1
  Removing intermediate container 56bd408c2eb1
   ---&gt; 4c4025bf5f64
  Step 6/8 : RUN chmod +x /apps/demo/initialize_env.sh
   ---&gt; Running in 18dc3a5c1a54
  Removing intermediate container 18dc3a5c1a54
   ---&gt; 60d2037a0209
  Step 7/8 : RUN ./initialize_env.sh $docker_image
   ---&gt; Running in 2e049b2cf630
  docker image is 
  ./initialize_env.sh: 5: ./initialize_env.sh: Syntax error: word unexpected (expecting ")")
  The command '/bin/sh -c ./initialize_env.sh $docker_image' returned a non-zero code: 2
  </code></pre>
  
  <p>When I execute separately the script, it works, but it doesn't inside the docker container.</p>