Dockerfile with ENTRYPOINT

Let’s rebuild the get-time image using an ENTRYPOINT.

FROM debian
COPY /usr/local/bin
RUN chmod +x /usr/local/bin/
ENTRYPOINT [ "/usr/local/bin/" ]

Rebuild the Docker image.

docker build -f Dockerfile.using_entrypoint -t get-time .

Now run a container.

docker run -it --rm --name timectr get-time
Fetch UTC(NIST) time every 5 seconds...
21-09-02 19:30:53

So far the behavior seems the same. However, unlike with CMD, arguments don’t override the ENTRYPOINT; instead, they are passed to. This behavior is more aligned with our expectations for containers that run specific programs.

docker run -it --rm --name timectr get-time 2
Fetch UTC(NIST) time every 2 seconds...
21-09-02 19:33:26
21-09-02 19:33:28