docker-compose 重启容器失败 docker 无法停止容器
2024-11-21 09:25:53 # Technical # Docker

起因

在一台资源紧张的服务器上使用 docker-compose 更新服务时,出现异常:

1
2
3
4
5
ERROR: for <server-name> UnixHTTPConnectionPool(host='localhost', port=None): Read timed out=70)

ERROR: for <server-name> UnixHTTPConnectionPool(host='localhost', port=None): Read timed out=70)
ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60).

尝试 docker stop rm

通过 docker ps 发现这个需要更新的服务任然存在

于是尝试通过 docker stop 停止后,然后 docker rm 干掉,最后 docker-compose up -d 启动

但尝试并未成功

docker rm 报错:

1
Error response from daemon: You cannot remove a running container 9be60403c53a64438a7153af2467f8318a. Stop the container before attempting removal or force remove

docker rm -f

根据报错的提示,使用 docker rm -f 强制删除容器

这一步执行正常,并成功删除了容器

启动失败

尝试启一个新的容器 docker-compose up -d 时,出现开头的异常

解决

查看 docker 网络

1
2
3
4
5
6
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
8262507c56bb bridge bridge local
107fbbe8c093 host host local
59d09ff8c0f0 none null local
c1fa9073e137 opt_default bridge local

找到异常中出现的 host

断开之前容器的连接

1
$ docker network disconnet --force host <server-name>