Docker Build: I made my Dockerfile Immutable

Girish V P
ADIBI Technologies, Basavanagudi, Blore.
1 min readMar 13, 2024

--

Some times it is good to keep a main configuration file immutable. Many a times multiple members and teams are involved in a software development environment. Here, I wanted to avoid hard cording of the Dockerfile and at the same time a flexibility of calling the build argument from my shell script.

Step 1: I Created a Dockerfile like below. PLATFORM is the build argument that need to be passed later point of time

FROM centos:7
COPY script.sh .
ARG PLATFORM
ENV PLATFORM=${PLATFORM}
ENTRYPOINT bash script.sh $PLATFORM

Step 2: Then I created a bash script file script.sh like below. “$1” is evaluated against the value passed later during the build.

#!/bin/bash
if [ $1 == "Linux" ]
then
echo "TEST: Build arguement was passed correctly"
else
echo "Bulid arguement was not passed correctly"
fi

Step 3: Then docker was built the by passing the argument.

Disclaimer: It is recommended to do a thorough test before applying in production environment.

--

--