'how to open a file and read contents inside the Dockerfile

I have a docker file where i need to open a file and get the data .If the data is dev, i am passing a argument(dev application) and if it is not passing another argument(prod application)to the sh file. It should be something like

f=open config.txt
data=f.read()
if data=dev
app=dev application
else
app=prod application

ENTRYPOINT ["./entry.sh app"]

here i am trying to pass the argument to the .sh file (entry.sh).so i can use the incoming argument in the entry.sh file. Please help me how to do it in a correct way. I am new to this Dockerfile.



Solution 1:[1]

You can pass arguments while building the docker image by using the ARG parameters like this. while building you can pass values like docker build --build-arg ENV_ARG=dev

DOCKER FILE CODE SAMPLE

ARG ENV_ARG=prod
ENV ENVIRONMENT=$ENV_ARG
CMD ["sh", "-c", "entry.sh ${ENVIRONMENT}"]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jijo Alexander