All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

Define a command for a container

Last updated:2021-05-11 10:41:27

When you run a container, the default command provided by the container image is run by default. If you want to run a specific command or override the defaults provided by the container image, you can define these fields:

  • workingDir: the working directory to run the command.
  • command: the command to run.
  • args: the arguments for the command.

Specify a working directory

You can specify a working directory to run the command that you define for a container. If the container image does not provide a working directory and you do not specify it in the KCE console either, the command is run in the root directory (/) of the container by default.

Define a command and arguments for a container

A Docker image stores image metadata, including the ENTRYPOINT and CMD fields that specify a default command and its arguments respectively. When a container is run with the Docker image, the default command is run with the specified arguments. You can set the command and args fields in the configuration file of a container to define a command and arguments for the container. The command and arguments that you define override the defaults of ENTRYPOINT and CMD in the Docker image. For more information, see ENTRYPOINT and CMD.

When you override the default ENTRYPOINT and CMD, these rules apply:

  • If you do not supply a command or args for a container, the defaults defined in the Docker image are used.
  • If you supply a command but no args for a container, only the supplied command is used. The default ENTRYPOINT and CMD defined in the Docker image are ignored.
  • If you supply only args for a container, the default ENTRYPOINT defined in the Docker image is run with the args that you supplied.
  • If you supply a command and args, the default ENTRYPOINT and CMD defined in the Docker image are ignored. Your command is run with your args.

The following table provides some examples.

Image ENTRYPOINT Image CMD Container command Container args Command run
[touch] [/usr/test] Not set Not set [touch /usr/test]
[touch] [/usr/test] [mkdir] Not set [mkdir]
[touch] [/usr/test] Not set [opt/test] [touch /opt/test]
[touch] [/usr/test] [mkdir] [opt/test] [mkdir /opt/test]
On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback