Cloud and Container Basics

FROM alpine
ENTRYPOINT ["ping", "-c", "3"]
CMD ["localhost"]

An image named pinger, built from the Dockerfile above, is started with docker run pinger example.com. Which of the following is the command executed in the container?

  1. Aping -c 3 localhost
  2. Bping -c 3 example.com
  3. Cexample.com (an attempt to run it as a command fails with an error)
Show answer and explanation

Answer: B. ping -c 3 example.com

An ENTRYPOINT written in exec form (a JSON array) is the command the container always runs, and CMD supplies its default arguments. Arguments written after the image name in docker run replace CMD and are appended after the ENTRYPOINT, so ping -c 3 example.com is executed. Started without arguments as docker run pinger, the localhost in CMD would be used, giving ping -c 3 localhost. To change the ENTRYPOINT itself, use the --entrypoint option of docker run.

  • A. This is what happens when the container is started without arguments. The arguments of docker run replace CMD.
  • B. Correct. The argument example.com replaces localhost in CMD and is appended after the ENTRYPOINT.
  • C. This would happen with an image that has only CMD and no ENTRYPOINT, because the argument would replace the whole command. Here there is an ENTRYPOINT, so it is passed as an argument.
Practice this topic Back to topic

Books on Cloud and Container Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Cloud and Container Basics questions

  1. A container is started with the command above from the image nginx, a web server that listens on port 80. The host's IP address is 192.0.2.10, and there are no restrictions such as a firewall. Which of the following is the URL to use to reach this web server from a browser on another PC on the same network?
  2. Dockerfile (B) above was made from Dockerfile (A), which had RUN npm ci after COPY . ., by changing the order so that only the dependency files are copied first. npm ci takes 120 seconds, npm run build 30 seconds and COPY . . 2 seconds, and the time of the other instructions is negligible. The image is rebuilt 20 times a day after changing only the source code under src (package.json and package-lock.json are unchanged). When the cache from the previous build can be used, which of the following is how much shorter B is than A in total build time per day?
  3. In Docker, which of the following correctly describes named volumes and bind mounts, used to keep data written by a container?
  4. An image is pulled by specifying registry.example.com/team/web:1.4. Which of the following correctly gives the meaning of each part of this reference?
  5. scratch is an empty image that contains no files. Which of the following correctly describes what the final image built with the multi-stage Dockerfile above contains?