docker start/stop/restart command
docker startThe command is used to start one or more already created containers.
docker stopThe command is used to stop a running container.
docker restartThe command is used to restart the container.
docker start Command
Syntax
docker start [OPTIONS] CONTAINER [CONTAINER...]
Parameter
-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 the container:
docker start -a my_container
Start the container and attach to its standard input and output streams.
Start multiple containers simultaneously:
docker start container1 container2 container3
Simultaneously start the containers container1, container2, and container3.
docker stop Command
Syntax
docker stop [OPTIONS] CONTAINER [CONTAINER...]
Parameter
-t, --time: The number of seconds to wait before stopping the container; the default is 10 seconds.
Example
Stop a container:
docker stop my_container
Stop the container named my_container.
Stop the container with a specified wait time:
docker stop -t 30 my_container
Stop the container after waiting 30 seconds.
Stop multiple containers simultaneously:
docker stop container1 container2 container3
Stop the containers container1, container2, and container3 simultaneously.
docker restart command
Syntax
docker restart [OPTIONS] CONTAINER [CONTAINER...]
Parameter
-t, --time: The number of seconds to wait before restarting the container; the default is 10 seconds.
Example
Restart a container:
docker restart my_container
Restart the container named my_container.
Restart the container with a specified wait time:
docker restart -t 15 my_container
Restart the container after waiting 15 seconds.
Restart multiple containers simultaneously:
docker restart container1 container2 container3
Restart the containers container1, container2, and container3 simultaneously.
other extensions