Cannot pass ENV variable through ENTRYPOINT exec command to a startup.sh file

I am having problem passing ENV variable which I have defined in Dockerfile. Here is the section of Dockerfile

The Dockefile is as shown below

################################################################

Sets the Base image

FROM openjdk:8-jre

LABEL maintainer=“user_email”

The first file should be be the main application called by the startup script

The second file should be the startup script

Include all other necessary files here and add them to the image and change their permissions below

ENV RELEASE_VERSION ${release_version}

ENV JAR_NAME ${jar_name}

ENV FILE1 ${JAR_NAME}

ENV FILE2 startup.sh

ENV FILE3 downselection.py

ENV FILE4 sql_py.py

ENV WORK_DIR /opt/serimmune/

Installs cloud-sql

RUN apt-get update \

&& apt-get install -y wget \

&& mkdir -p ${WORK_DIR}proxy \

&& wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O ${WORK_DIR}proxy/cloud_sql_proxy \

&& chmod +x ${WORK_DIR}proxy/cloud_sql_proxy;

Installs python and necessary python packages

RUN apt-get update \

&& apt-get install -y python3-pip \

&& apt-get install -y python-mysqldb \

&& pip3 install mysql-connector-python \

&& pip3 install numpy \

&& pip3 install scipy \

&& pip3 install pandas==0.23.4 \

&& pip3 install scikit-learn \

&& pip3 install xlrd \

&& pip3 install openpyxl;

Exposes port 3306 for MySQL

EXPOSE 3306

Copies necessary files into image

COPY build/libs/{FILE1} {WORK_DIR}

COPY {FILE2} {WORK_DIR}

COPY {FILE3} {WORK_DIR}

COPY {FILE4} {WORK_DIR}

Changes the permissions of those files

RUN chmod +x {WORK_DIR}{FILE1}

RUN chmod +x {WORK_DIR}{FILE2}

RUN chmod +x {WORK_DIR}{FILE3}

RUN chmod +x {WORK_DIR}{FILE4}

Sets the startup script as what the container will first run

#ENTRYPOINT ["/bin/bash", “-c”, “/opt/serimmune/startup.sh $RELEASE_VERSION”]

ENTRYPOINT exec /opt/serimmune/startup.sh $RELEASE_VERSION

CMD ["", “”]

##################################################################
Any suggestion The startup,sh needs to get $RELEASE_VERSION as input parameter so it can make jar file name with version number.

What am I doing wrong??

Thanks,

Vikram

Hello vmahuvakar,

On the top section about environment variables you need to use the ARG name = default value instruction on all your variables and inject them during build time with : docker build --build-arg varname = value

Check out this link : https://docs.docker.com/engine/reference/builder/

Best Regards,
Fouscou

hi, vmahuvakar.
You can try the follow:

  • Call to release_version into a startup file and just put ENTRYPOINT [“sh”,"/startup.sh"] in the end of docker file.
  • Make an other .sh file wich contain the “export” command, and after call de ENTRYPOINT with the enviroment variable.

The last work for me, but I had show enviroments variables before use them, with “printenv” command. Curiously.

Good Lucky.