You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行docker-compose down无法停止容器,终端卡顿求助

Docker Compose 无法停止容器且终端卡顿的解决办法

问题重现

执行docker-compose down时容器无法正常停止,报错如下:

nginx-nodejs-redis-web1-1   | Web application is listening on port 5000
nginx-nodejs-redis-web2-1   | Web application is listening on port 5000
nginx-nodejs-redis-nginx-1  | 172.18.0.1 - - [20/Jun/2024:05:40:49 +0000] "GET / HTTP/1.1" 200 28 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"
nginx-nodejs-redis-nginx-1  | 172.18.0.1 - - [20/Jun/2024:05:40:49 +0000] "GET /favicon.ico HTTP/1.1" 404 150 "http://localhost:8080/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"
nginx-nodejs-redis-nginx-1  | 172.18.0.1 - - [20/Jun/2024:05:40:52 +0000] "GET / HTTP/1.1" 200 28 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"
nginx-nodejs-redis-nginx-1  | 172.18.0.1 - - [20/Jun/2024:05:40:53 +0000] "GET / HTTP/1.1" 200 28 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"
nginx-nodejs-redis-nginx-1  | 172.18.0.1 - - [20/Jun/2024:05:40:54 +0000] "GET / HTTP/1.1" 200 28 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"
nginx-nodejs-redis-nginx-1  | 172.18.0.1 - - [20/Jun/2024:05:40:55 +0000] "GET / HTTP/1.1" 200 28 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"
^CGracefully stopping... (press Ctrl+C again to force)
[+] Running 0/2
 ⠿ Container nginx-nodejs-redis-redis-1  Error while Stopping                                                                                                                               14.0s
 ⠿ Container nginx-nodejs-redis-nginx-1  Error while Stopping                                                                                                                               14.0s
[+] Running 0/4
 ⠿ Container nginx-nodejs-redis-web1-1   Error while Killing                                                                                                                                10.0s
 ⠿ Container nginx-nodejs-redis-nginx-1  Error while Killing                                                                                                                                10.0s
 ⠿ Container nginx-nodejs-redis-redis-1  Error while Killing                                                                                                                                10.0s
 ⠿ Container nginx-nodejs-redis-web2-1   Error while Killing   
^C^C

之后终端卡顿,多次按Ctrl+C、Ctrl+D,输入exit都无法退出:

^C^Cexit
exit

解决步骤

  1. 打开新终端窗口:别在卡死的终端里耗着,直接开个新终端操作。
  2. 强制终止卡住的docker-compose进程:
    pkill -9 docker-compose
    
    执行完这条命令,原来卡死的终端就能恢复正常。
  3. 强制停止所有相关容器:
    用docker-compose自带的强制停止命令:
    docker-compose kill
    
    或者直接指定容器名强制终止:
    docker kill nginx-nodejs-redis-redis-1 nginx-nodejs-redis-nginx-1 nginx-nodejs-redis-web1-1 nginx-nodejs-redis-web2-1
    
  4. 清理容器与关联资源:
    容器停止后,执行命令清理网络、卷等资源:
    docker-compose down -v
    
    加-v参数可以同时删除关联的匿名卷,避免残留数据占用空间。

后续排查(可选)

如果频繁出现这类问题,建议检查:

  • 容器内的应用是否正确处理SIGTERM信号,导致无法优雅停止;
  • Docker或Docker Compose版本是否过旧,尝试升级到稳定版;
  • 宿主机CPU、内存、磁盘资源是否不足,导致进程响应缓慢。

内容的提问来源于stack exchange,提问作者void_meet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 03:04:57