K:Kubernetes/Docker EntryPoint and Cmd

 

In Docker:

  • ENTRYPOINT: Defines the main command that runs when the container starts. It cannot be easily overridden directly from the command line.
  • CMD: Provides default arguments for the ENTRYPOINT or defines a command to run if no ENTRYPOINT is specified. It can be overridden by passing arguments to docker run.

In Kubernetes:

  • command (in the Pod specification): This field overrides the ENTRYPOINT specified in the Dockerfile.
  • args (in the Pod specification): This field overrides the CMD specified in the Dockerfile.

Example Dockerfile:

Dockerfile
FROM ubuntu ENTRYPOINT ["echo"] CMD ["Hello, World!"]

Running with Docker:

  • Default behavior: docker run myimage will output Hello, World!.
  • Overriding CMD: docker run myimage Kubernetes will output Kubernetes.
  • Overriding ENTRYPOINT: Not directly possible via command line (requires a change in the Dockerfile or using the --entrypoint flag).

Running in Kubernetes:

yaml
apiVersion: v1 kind: Pod metadata: name: example-pod spec: containers: - name: example-container image: myimage command: ["echo"] args: ["Kubernetes is awesome!"]
  • command field: Overrides the ENTRYPOINT (echo in this example).
  • args field: Overrides the CMD ("Kubernetes is awesome!" instead of "Hello, World!").

Key Points:

  • Overriding in Docker: You can override CMD by passing arguments to docker run. Overriding ENTRYPOINT requires the --entrypoint flag.
  • Overriding in Kubernetes: You can override both ENTRYPOINT (using command) and CMD (using args) in the Pod specification.

Therefore, Kubernetes provides a more flexible way to control container startup commands directly through the Pod configuration, without needing to modify the Dockerfile or use specific command-line flags like in Docker.

Comments

Popular posts from this blog

KB: Azure ACA Container fails to start (no User Assigned or Delegated Managed Identity found for specified ClientId)

Electron Process Execution Failure with FSLogix

KB:RMM VS DEX (Remote Monitoring Management vs Digital Employee Experience)