My environment variable file located in docker image but i want to change that env paramater while runing as container

Hi Team, i am deploying a React app env file stored at /usr/share/nginx/html/environment_varibles.js file I replacd that value while building a docker image. its working fine but, while running that image as container i want to change that env parameter value.

here is my docker file.

and i tried while deploying that as

docker run -d --name react-ui -e REACT_APP_DOMAIN=“https://client-dev.indu.com” -p 8080:80 react

but it was not reflecting at /usr/share/nginx/html/environment_varibles.js this file.

can anyone help to solve this.

Your approach to set an environment in the image, and override it for the container is correct. And it is exactly what you do! Nothing more, nothing less.

Though, your expectation that it would do anything on it’s on is incorrect. If you docker exec into your container, and type echo ${REACT_ADD_DOMAIN}, you will see it worked.

If you want to modify a file based on the value of the environment variable, then you need to create an entrypoint script and implement that logic to actually modify the file (make sure to run nginx at the end of your script; exec nginx -g daemon off;), copy the script into the image (make it executable if necessary) and then declare it as ENTRYPOINT.

As @meyay explained it sets the variable in the container and you could indeed create an entrypoint, however, since you actually used the ARG instruction which sets the default value of a build argument, you can change the file by rebuilding the image with an overridden argument:

docker build . -t your_image_name --build-arg "REACT_APP_DOMAIN=https://client-dev.indu.com"

and run the container from the new version.

Note: Using code blocks (</> button) make your post much readable instead of sharing images or inserting commands with links that will be interpreted by the forum

I modified my docker file as shown below, there is no result.

while deploying that image got an error as (sed: bad option in substitution expression)

Please share the content as text in a Preformatted text block (gear icon → </> icon).
Furthermore, please describe what you did.

You should invest more time in learning instead of changing a RUN instruction to be an entrypoint. This is not what an entrypoint should be and doesn’t make sense at all. I shared an almost “copy-paste” solution with you which doesn’t require changing the Dockerfile and you have chosen to change the Dockerfile although it seems you know nothing about the entrypoint instruction. If you search for it you will find plenty of blog posts but you can also read the documentation:

https://docs.docker.com/engine/reference/builder/#entrypoint

By the way I barely noticed the entrypoint line on the picture. Please listen to us so we can help you.

I expected a solution and root cause How ever I resolved that issue by adding CMD in that CMD added sed expression. I got an expected output. Thanks for your response.