The ENTRYPOINT instruction

The ENTRYPOINT instruction is used to configure a docker image to run like an application or a command. For example, we can use the ENTRYPOINT instruction to make an image that displays help for the curl command. Consider this Dockerfile:

# ENTRYPOINT instruction Dockerfile for Docker Quick Start
FROM alpine
RUN apk add curl
ENTRYPOINT ["curl"]
CMD ["--help"]

We can run the container image with no overriding CMD parameter and it will show help for the curl command. However, when we run the container with a CMD override parameter, in this case, a URL, the response will be to curl the URL. Take a look:

When run parameters are provided to a container that has the exec form of the ENTRYPOINT command, those parameters will be appended to the ENTRYPOINT instruction, overriding anything provided in a CMD instruction. In this example, --help is overridden with the google.com run parameter, so the resulting instruction is curl google.com. Here is the actual syntax for the ENTRYPOINT instruction:

# ENTRYPOINT instruction syntax
ENTRYPOINT command param1 param2 (shell form)
ENTRYPOINT ["executable", "param1", "param2"] (exec form, best practice)

Like the CMD instruction, only the last ENTRYPOINT instruction is significant. Again, this allows you to either use or override the ENTRYPOINT instruction in the FROM image used. Like both the RUN and CMD instructions, using the shell form will invoke a shell as ["/bin/sh", "-c"] (or ["cmd", "/S", "/C"] on Windows). This is not the case when using the exec form of the instruction. This is key if you have an image that does not have a shell or if the shell is not available to the active user context. However, you will not get shell processing, so any shell environment variables will not get substituted when using the exec form of the instruction. It is generally considered best practice to use the exec form of the ENTRYPOINT instruction whenever possible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset