I would like to pass argument (from the docker command) to the shell script inside the Dockerfile.
This is the docker command line.
docker build --file=DockerfileTest --build-arg docker_image=PX-release-migration --tag=test-image:latest --rm=true . This is a script that is called inside the Dockerfile.
#!/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 When I execute separately the script, it works, but it doe
This is docker file.
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}" 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.
This is the error message that I am getting.
Step 1/8 : ARG spring_env=local Step 2/8 : ARG docker_image=-local- Step 3/8 : FROM maven:3.6.1-jdk-8 ---> 4c81be38db66 Step 4/8 : COPY . /apps/demo ---> 41439197c465 Step 5/8 : WORKDIR /apps/demo ---> Running in 56bd408c2eb1 Removing intermediate container 56bd408c2eb1 ---> 4c4025bf5f64 Step 6/8 : RUN chmod +x /apps/demo/initialize_env.sh ---> Running in 18dc3a5c1a54 Removing intermediate container 18dc3a5c1a54 ---> 60d2037a0209 Step 7/8 : RUN ./initialize_env.sh $docker_image ---> 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 When I execute separately the script, it works, but it doesn't inside the docker container.