Dockerfile with both
What if we want to override the container to behave the way it does with an
ENTRYPOINT
, but we want to override the default frequency of 5
seconds?
You use both ENTRYPOINT
and CMD
.
FROM debian
COPY get-time.sh /usr/local/bin
RUN chmod +x /usr/local/bin/get-time.sh
ENTRYPOINT [ "/usr/local/bin/get-time.sh" ]
CMD [ "2" ]
Rebuild the Docker image.
docker build -f Dockerfile.using_entrypoint -t get-time .
Run a container.
docker run -it --rm --name timectr get-time
Fetch UTC(NIST) time every 2 seconds...
21-09-02 19:30:53
^C
What happens here is that the value for CMD
acts as a default argument that
will be passed to the command specified by ENTRYPOINT
. You can still pass an
argument when you create the container and it will just override CMD
’s default
value.
docker run -it --rm --name timectr get-time 3
Fetch UTC(NIST) time every 3 seconds...
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.