<p>I have a major problem and will do my best to be short in the explanation. I am running a cronjob on an endpoint and would like to containerize that process. The endpoint needs to have some environments variables set and obviously a <code>TOKEN</code> authentication which is basically the login before I can curl POST or GET to get what I want from the API. The tricky part is that that TOKEN is never the same which means I need to run a curl command to get it during the pod run time. To make sure those environments variables are there in run time I injected a command in the cronjob args field to keep it running. When I ssh to the pod all my all env var are there ;) but the <code>TOKEN</code> :( . When I run <code>./run.sh</code> from inside the pod nothing happens which is the reason the TOKEN isn't listed in <code>printenv</code>. However when I manually run <code>command 1</code> then <code>command 2</code> from inside the pod it works fine. I am very confused and please help me if you can please. Instead of running my commands as a bash in the <code>cmd</code> at the docker level, I have seen that I can possibly parse <code>command 1</code> and <code>command 2</code> from the <code>run.sh</code> inside my cronjob.yaml with a multi line block scalar but haven't figured how as yaml format are a pain. Below are my codes for more details:</p>
<p><strong>docker-entrypoint.sh</strong> --&gt; removed</p>
<pre><code>#! /bin/sh
export AWS_REGION=$AWS_REGION
export API_VS_HD=$API_VS_HD
export CONTROLLER_IP=$CONTROLLER_IP
export PASSWORD=$PASSWORD
export UUID=$UUID
</code></pre>
<p><strong>Dockerfile</strong></p>
<pre><code>FROM harbor/ops5/private/:device-purge/python38:3.8

# Use root user for packages installation
USER root

# Install packages
RUN yum update -y &amp;&amp; yum upgrade -y

# Install curl
RUN yum install curl -y \
    &amp;&amp; curl --version

# Install zip/unzip/gunzip
RUN yum install zip unzip -y \
    &amp;&amp; yum install gzip -y

# Install wget 
RUN yum install wget -y

# Install jq
RUN wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
RUN chmod +x ./jq
RUN cp jq /usr/bin

# Install aws cli
RUN curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;
RUN unzip awscliv2.zip
RUN ./aws/install

# Set working directory
WORKDIR /home/app

# Add user
RUN groupadd --system user &amp;&amp; adduser --system user --no-create-home --gid user
RUN chown -R user:user /home/app &amp;&amp; chmod -R 777 /home/app

# Copy app
COPY ./run.sh /home/app 
RUN chmod +x /home/app/run.sh

# Switch to non-root user
USER user

# Run service
CMD [&quot;sh&quot;, &quot;-c&quot;, &quot;./run.sh&quot;]
</code></pre>
<p><strong>run.sh</strong></p>
<pre><code># Command 1
export TOKEN=`curl -H &quot;Content-Type: application/json&quot; -H &quot;${API_VS_HD}&quot; --request POST --data &quot;{\&quot;providerName\&quot;:\&quot;local\&quot;,\&quot;username\&quot;:\&quot;admin\&quot;,\&quot;password\&quot;:\&quot;$PASSWORD\&quot;,\&quot;deviceId\&quot;:\&quot;$UUID\&quot;}&quot; https://$CONTROLLER_IP:444/admin/login --insecure | jq -r '.token'`

# Sleep 
sleep 3

# Command 2
curl -k -H &quot;Content-Type: application/json&quot; \
         -H &quot;$API_VS_HD&quot; \
         -H &quot;Authorization: Bearer $TOKEN&quot; \
         -X GET \
         https://$CONTROLLER_IP:444/admin/license/users

</code></pre>
<p>cronjob.yaml</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: device-cron-job
  namespace: device-purge
spec:
  schedule: &quot;*/2 * * * *&quot; # test
  jobTemplate:
    spec:
      template:
        spec:
          imagePullSecrets:
          - name: cron
          containers:
          - name: device-cron-pod
            image: harbor/ops5/private/:device-purge
            env:
            - name: AWS_REGION
              value: &quot;us-east-1&quot;
            - name: API_VS_HD
              value: &quot;Accept:application/vnd.appgate.peer-v13+json&quot;
            - name: CONTROLLER_IP
              value: &quot;52.61.245.214&quot;
            - name: UUID
              value: &quot;d2b78ec2-####-###-###-#########&quot;
            - name: PASSWORD
              valueFrom:
                secretKeyRef: 
                  name: password
                  key: password
            imagePullPolicy: Always
          restartPolicy: OnFailure
      backoffLimit: 3
</code></pre>

<p><code>run.sh</code> is never being called.  <code>docker-entrypoint.sh</code> needs to exec <code>run.sh</code> by adding <code>exec $@</code> at the bottom.  But you don't really need the entrypoint anyways, those environment variables are already being exported into your environment by docker.  I'm also not sure why you are specifying <code>command</code> and <code>args</code> in your yaml spec but I would get rid of those.</p>
<p>When you provide both an <code>ENTRYPOINT</code> and a <code>CMD</code> command in this form, the <code>CMD</code> params are passed to the entrypoint file, which then has the responsibility of executing the necessary process.  You can review the documentation <a href="https://docs.docker.com/engine/reference/builder/#cmd" rel="nofollow noreferrer">here</a>.</p>
