Concepts

Detailed explanations of Kubernetes system concepts and abstractions.

Documentation for Kubernetes v1.5 is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.

Edit This Page

Container Command and Arguments

In the configuration file for a Container, you can set the command and args fields to override the default Entrypoint and Cmd of the the Container’s image.

Container entry points and arguments

The configuration file for a Container has an image field that specifies the Docker image to be run in the Container. A Docker image has metadata that includes a default Entrypoint and a default Cmd.

When Kubernetes starts a Container, it runs the image’s default Entrypoint and passes the image’s default Cmd as arguments.

If you want override the image’s default Entrypoint and Cmd, you can use the command and args fields in the Container’s configuration.

This table summarizes the field names used by Docker and Kubernetes.

Description Docker field name Kubernetes field name
The command run by the container Entrypoint command
The arguments passed to the command Cmd args

Here’s an example of a configuration file for a Pod that has one Container.

commands.yaml
apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: ["printenv"]
    args: ["HOSTNAME", "KUBERNETES_PORT"]

When Kubernetes starts the Container, it runs this command:

printenv HOSTNAME KUBERNETES_PORT

When you override the default Entrypoint and Cmd, these rules apply:

Here are some examples:

Image Entrypoint Image Cmd Container command Container args Command run
[/ep-1] [foo bar] <not set> <not set> [ep-1 foo bar]
[/ep-1] [foo bar] [/ep-2] <not set> [ep-2]
[/ep-1] [foo bar] <not set> [zoo boo] [ep-1 zoo boo]
[/ep-1] [foo bar] [/ep-2] [zoo boo] [ep-2 zoo boo]

What’s next

Analytics

Create an Issue Edit this Page