Which statement best describes the difference between ENTRYPOINT and CMD in a Dockerfile?
Think about which instruction defines the fixed command and which one sets default parameters.
ENTRYPOINT defines the executable that always runs when the container starts. CMD provides default arguments to ENTRYPOINT or runs a command if ENTRYPOINT is not set. CMD can be overridden by command line arguments when running the container.
Given this Dockerfile snippet, what will be the output when running docker run myimage?
ENTRYPOINT ["echo"] CMD ["Hello World"]
Remember how ENTRYPOINT and CMD combine when both are arrays.
ENTRYPOINT sets the command echo. CMD provides the default argument Hello World. Running the container executes echo Hello World, printing Hello World.
You want a Docker container that always runs python3 but allows users to pass different scripts or arguments when running the container. Which Dockerfile setup achieves this?
Think about which instruction fixes the executable and which provides default arguments.
Setting ENTRYPOINT to python3 fixes the executable. CMD provides a default script script.py. Users can override script.py by passing arguments to docker run.
You have this Dockerfile:
ENTRYPOINT ["/bin/bash"] CMD ["-c", "echo Hello"]
Running docker run myimage ls does not list files but opens a bash shell. Why?
Consider how command line arguments interact with ENTRYPOINT and CMD.
ENTRYPOINT fixes the executable to /bin/bash. When you run docker run myimage ls, ls replaces the CMD arguments but does not change the ENTRYPOINT. So the container runs /bin/bash ls, which opens bash with ls as argument, not executing ls as a command.
You are creating a Docker image for a CLI tool. You want users to run commands like docker run tool image.jpg and have tool process image.jpg. Which Dockerfile setup is best?
Think about fixing the executable and allowing flexible arguments.
Setting ENTRYPOINT to the CLI tool executable fixes the command. CMD can provide default arguments or be empty. This lets users pass arguments like filenames when running the container, making it behave like a normal CLI tool.