docker start/stop/restart Command
docker start The command is used to start one or more containers that have already been created.
docker stop The command is used to stop a running container.
docker restart The command is used to restart containers.
docker start Command
Syntax
docker start [OPTIONS] CONTAINER [CONTAINER...]
Parameters
-a: Attach to the container's standard input and output streams.-i: Attach and keep standard input open.
Example
Start a container:
docker start my_container
Start the container named my_container.
Start and attach to a container:
docker start -a my_container
Start a container and attach to its standard input and output streams.
Start multiple containers simultaneously:
docker start container1 container2 container3
Simultaneously start the container1, container2, and container3 containers.
docker stop Command
Syntax
docker stop [OPTIONS] CONTAINER [CONTAINER...]
Parameters
-t, --time: The number of seconds to wait before stopping the container, 10 by default.
Example
Stop a container:
docker stop my_container
Stop the container named my_container.
Stop a container with a specified wait time:
docker stop -t 30 my_container
Wait 30 seconds before stopping the container.
Stop multiple containers simultaneously:
docker stop container1 container2 container3
Simultaneously stop the container1, container2, and container3 containers.
docker restart Command
Syntax
docker restart [OPTIONS] CONTAINER [CONTAINER...]
Parameters
-t, --time: The number of seconds to wait before restarting the container, 10 by default.
Example
Restart a container:
docker restart my_container
Restart the container named my_container.
Restart a container with a specified wait time:
docker restart -t 15 my_container
Wait 15 seconds before restarting the container.
Restart multiple containers simultaneously:
docker restart container1 container2 container3
Simultaneously restart the container1, container2, and container3 containers.
Docker Command Reference