Create a new container named web from nginx:latest and run it in the background.
Which command is appropriate?
docker run creates a new container from an image and starts it. -d detaches and --name assigns the container name.
Detailed explanation
docker run -d --name web nginx:latestCorrect. docker run -d --name web nginx:latest creates and starts the new container.
Correct. docker run -d --name web nginx:latest creates and starts the new container.
docker start nginx:latest --name webIncorrect. docker start operates on an existing container, not an image tag.
Incorrect. docker start operates on an existing container, not an image tag.
docker exec -d nginx:latest webIncorrect. docker exec runs a process in an existing container.
Incorrect. docker exec runs a process in an existing container.
docker ps --create webIncorrect. docker ps lists containers and does not create one.
Incorrect. docker ps lists containers and does not create one.
Try it yourself
An example you can run in a temporary verification environment.
docker run --help 2>/dev/null | head -n 5 || trueExpected result
Dockerがある場合はrunのhelp。containerは作成しないKey points
- docker run
- --name
- -d
Notes
- Environment: Docker CLI helpのみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.