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.
docker start nginx:latest --name webIncorrect. 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.
docker ps --create webIncorrect. 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のみ
- Use a disposable VM or container when validating lifecycle commands.
- Exact command output can vary slightly by distribution and runtime version.
Foundation review
Identify the layer
Creating, starting, attaching to, and listing containers are different Docker operations even when they appear in one workflow.
Check the side effect
Confirm the image tag and container name before starting a disposable test container.