1

i'm trying to pass the name of the script from the docker run but its not getting the script name in the cmd command.

Not sure what's wrong here, same thing works fine in springboot/java projects

enter image description here

enter image description here

Below is the docker file

FROM python:3.8.8

RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y nodejs  

RUN apt-get install -y npm 

WORKDIR  /rubix-kyc

COPY . /rubix-kyc

RUN pip install -r  /rubix-kyc/requirements.txt

ARG SCRIPT_NAME

ENV SCRIPT_NAME ${SCRIPT_NAME}

RUN mkdir -p video_recording/

RUN npm install

RUN npm install elastic-apm-node --save

EXPOSE 4443

CMD [ "npm", "run" , "${SCRIPT_NAME}"]

Updating the script for running docker.

docker run  \
-e SCRIPT_NAME=start-local \
-p 4443:4443 $1

Need you help here

3
  • Are you sure you're building your image with the build-arg set, e.g.: docker build --build-arg SCRIPT_NAME=example_script Commented Sep 20, 2022 at 18:06
  • Please post also your docker run command. Commented Sep 20, 2022 at 18:06
  • @m19v updated the script , please check once Commented Sep 21, 2022 at 11:31

1 Answer 1

1

For the variables used in CMD it is important to pass it as environment variable on docker run besides defining with ARG and assigning with ENV in Dockerfile, as it is evaluated on runtime, e.g.:

docker run --rm -ti -e SCRIPT_NAME=value-of-script-name <docker-image-id>

Please adjust your Dockerfile as well:

ARG SCRIPT_NAME
ENV SCRIPT_NAME=$SCRIPT_NAME
...
CMD npm run $SCRIPT_NAME
Sign up to request clarification or add additional context in comments.

4 Comments

i'm passing the argument in docker run command, Please check the script . I have updated in the question
Check the answer, i have adjusted it. I.e. adjust the line with ENV in Dockerfile as ENV SCRIPT_NAME=$SCRIPT_NAME
and CMD in Dockerfile
thank you so much it worked, haven't used --rm and -ti till date, Need to read more about that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.