ScanSkill

CMD

CMD is used to provide defaults for an executing container. There can only be a single CMD instruction in a Dockerfile. If more than one, the last one will take effect.

Syntax

# *exec* form, preferred one
CMD ["executable", "param1", "param2"]

# As default parameters to *ENTRYPOINT*
CMD ["param1", "param2"]

# *shell* form
CMD command param1 param2

Here, if CMD is used to provide default arguments for ENTRYPOINT instruction, both CMD and ENTRYPOINT instructions should be specified with the JSON array format.

Note: The exec form is parsed as JSON array, so you must use double-quotes (”) around the words.

Example

  • Using shell form:
FROM ubuntu
CMD echo "This is just a echoing text."
  • Using exec form(other than shell form). in this you should pass arguments as a JSON array format:
FROM ubuntu
CMD ["/usr/bin/wc", "--help"]