Difference between Docker ENTRYPOINT and Kubernetes container spec COMMAND?

Viewed 81033

Dockerfile has a parameter for ENTRYPOINT and while writing Kubernetes deployment YAML file, there is a parameter in Container spec for COMMAND.

I am not able to figure out what's the difference and how each is used?

4 Answers

The COMMAND in the YAML file overwrites anything mentioned in the ENTRYPOINT in the docker file.

Basically the COMMAND can override what is mentioned in the docker ENTRYPOINT

Simple example:

To override the dockerfile ENTRYPOINT, just add these fields to your K8s template (Look at the command and args):

apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: ["/bin/sh"]
    args: ["-c", "printenv; #OR WHATEVER COMMAND YOU WANT"]
  restartPolicy: OnFailure

K8s docs:

command field corresponds to entrypoint in some container runtimes. Refer to the Notes below.

You can enter Notes link (K8s documentation for better understanding on how this command overrides the K8s ENTRYPOINT)

Related