bitTater
bitTater

Reputation: 33

How do I make Timeout command from entrypoint in Dockerfile

I have been trying to run timeout command on my shellscript with time being passed as variabe through Dockerfile

This is my DokcerFile(sample)

FROM locustio/locust:1.2.3

ARG TIME_CHECK=15

COPY --chown=locust:locust ping.sh .

RUN echo  "Hello $TIME_CHECK"

RUN chown locust:locust /home/locust && chmod +x ./ping.sh

ENTRYPOINT ["/bin/bash","-c", "timeout $TIME_CHECK ./ping.sh"]

Docker build happens successfully with below command and I can the value being passed correctly

docker build -t pingit --build-arg TIME_CHECK=10

When I do docker run it fails with following error

Try 'timeout --help' for more information.

I do understand this is because ENTRYPOINT is not recogninsing variable as such.

What am I doing wrong can you anyone help me here.

Upvotes: 1

Views: 1589

Answers (2)

Tarun Lalwani
Tarun Lalwani

Reputation: 146540

Just add a ENV TIME_CHECK=$TIME_CHECK to your dockerfile after the ARG statement.

The issue is that ARG is at build time. If you need to use it as environment variable then you need to set the variable yourself

Upvotes: 0

gongshw
gongshw

Reputation: 872

From docker reference, you can only access ARG values at build-time.

To pass a value to the runtime environment variable, you can use ENV instruction:

FROM locustio/locust:1.2.3

ARG TIME_CHECK=15

# assign ENV from ARG
ENV TIME_CHECK=${TIME_CHECK}

COPY --chown=locust:locust ping.sh .

RUN echo  "Hello $TIME_CHECK"

RUN chown locust:locust /home/locust && chmod +x ./ping.sh

ENTRYPOINT ["/bin/bash","-c", "timeout $TIME_CHECK ./ping.sh"]

Upvotes: 1

Related Questions