Docker provides several commands that you can use to manage containers, including commands to stop, start, and remove containers. Here are some examples:
Stop a running container: To stop a running container, use the docker stop command followed by the container ID or name. For example:
docker stop my-container
This command stops the container with the name my-container.
Start a stopped container: To start a stopped container, use the docker start command followed by the container ID or name. For example:
docker start my-container
This command starts the container with the name my-container.
Remove a container: To remove a container, use the docker rm command followed by the container ID or name. For example:
docker rm my-container
This command removes the container with the name my-container. If the container is running, you need to stop it before removing it.
In addition to these basic commands, Docker provides a number of other commands that you can use to manage containers. Here are some examples:
List running containers: To list the containers that are currently running, use the docker ps command. For example:
docker ps
This command lists the containers that are currently running, along with their ID, name, image, status, and other information.
List all containers: To list all of the containers, including those that are stopped, use the docker ps -a command. For example:
docker ps -a
This command lists all of the containers, including those that are running and those that are stopped.
Force remove a container: To force remove a container, use the docker rm -f command followed by the container ID or name. For example:
docker rm -f my-container
This command forcefully removes the container with the name my-container, even if it is currently running.
Stop and remove all containers: To stop and remove all of the containers, use the docker container prune command. For example:
docker container prune
This command stops and removes all of the containers that are not currently running, freeing up disk space and resources.
Overall, Docker provides a number of commands that you can use to manage containers, including commands to stop, start, and remove containers. By using these commands, you can easily manage containers and ensure that your applications are running smoothly.