What does the CMD instruction in a Dockerfile define
Question
What does the CMD instruction in a Dockerfile define
Solution
The CMD instruction in a Dockerfile provides defaults for an executing container. These can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction.
There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction.
CMD has three forms:
- CMD ["executable","param1","param2"] (exec form, this is the preferred form)
- CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
- CMD command param1 param2 (shell form)
When used in the shell or exec formats, the CMD instruction sets the command to be executed when running the image.
If you use the shell form of the CMD, then the <command> will execute in /bin/sh -c:
For example:
CMD echo "This is a test." | wc -
If you use the exec form, it is recommended to be CMD ["executable","param1","param2"].
For example:
CMD ["echo", "This is a test."]
Similar Questions
What is the purpose of a Dockerfile?(1 Point)To define a Docker containerTo define a Docker imageTo manage Docker networksTo manage Docker volumes
Question 2What does the Docker build command do?0 / 1 pointPulls an image from a registryPushes a local image to a registryCreates an image from a DockerfileRuns a container interactively
What does the Docker Compose 'down' command do?
What does the following Docker command do?docker run -i -t alpine /bin/bashRuns the image as a containerSetup /bin/bash in the containerStarts Docker in alpine modeThis Dockerfile is not valid
Which command is used to create a new Docker image?(1 Point)docker builddocker pulldocker rundocker commit
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.