A staging server needs to run a database from a prebuilt container image. The service must operate in the background, listen on host port 5432, use the name stagedb, and restart automatically on host reboot. Which command fulfills these requirements?
docker run --name stagedb -p 5432:5432 postgres:13
The correct command uses docker run to create and start the container. The -d flag runs the container in detached (background) mode. The --name flag assigns the required name stagedb. The -p 5432:5432 flag maps the host's port to the container's port. The --restart unless-stopped policy ensures the container will restart automatically with the Docker daemon (e.g., on host reboot) unless it was explicitly stopped.
One incorrect command omits the -d and --restart flags, which means it would run in the foreground and would not be configured to restart on reboot.
Another incorrect option uses docker start. This command is for restarting an existing, stopped container; it cannot be used to create a new container from an image or with creation-time flags like --name or -p.
The final incorrect option includes the --rm flag, which automatically removes a container when it stops. This flag conflicts with any --restart policy and will cause the command to fail.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `-d` flag in the `docker run` command do?
Open an interactive chat with Bash
Why is the `--restart unless-stopped` flag important in the `docker run` command?
Open an interactive chat with Bash
How does the `-p 5432:5432` option work in the `docker run` command?