Home > Blockchain >  Docker Environment variable not working in CMD
Docker Environment variable not working in CMD

Time:09-22

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

CodePudding user response:

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
  • Related