3.4 KiB
| title | redirect_from | ||
|---|---|---|---|
| Container Command and Arguments |
|
{% capture overview %}
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.
{% endcapture %}
{% capture body %}
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.
- The
commandfield specifies the actual command run by the Container. - The
argsfield specifies the arguments passed to the command.
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.
{% include code.html language="yaml" file="commands.yaml" ghlink="/docs/concepts/configuration/commands.yaml" %}
When Kubernetes starts the Container, it runs this command:
printenv HOSTNAME KUBERNETES_PORT
When you override the default Entrypoint and Cmd, these rules apply:
-
If you do not supply
commandorargsfor a Container, the defaults defined in the Docker image are used. -
If you supply a
commandbut noargsfor a Container, only the suppliedcommandis used. The default EntryPoint and the default Cmd defined in the Docker image are ignored. -
If you supply only
argsfor a Container, the default Entrypoint defined in the Docker image is run with theargsthat you supplied. -
If you supply a
commandandargs, the default Entrypoint and the default Cmd defined in the Docker image are ignored. Yourcommandis run with yourargs.
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] |
{% endcapture %}
{% capture whatsnext %}
{% endcapture %}
{% include templates/concept.md %}