docker/stop

Stop Container

Stop one or more running containers gracefully.

container
lifecycle

Command

docker stop

Explanation

docker stop allows containers to finish tasks and shut down gracefully. If they fail to stop within the default 10 seconds, Docker sends SIGKILL to force termination. This ensures data integrity and avoids corrupted states.

Common Use Cases

  • Gracefully shutting down running containers
  • Stopping all active containers before system maintenance
  • Preventing data loss in production containers

Best Practices

  • Always stop containers gracefully before removal
  • Use docker ps to confirm containers are stopped

Common Mistakes to Avoid

  • Using docker kill instead of docker stop, causing unclean shutdowns
  • Stopping containers without confirming dependencies

Troubleshooting

Problem: Container doesn’t stop

Solution: Use docker stop -t <seconds> to extend timeout or docker kill to force.

Examples

Gracefully stop container

docker stop my_container

Stop all running containers

docker stop $(docker ps -q)