docker - 运行和停止 Alpine Docker 容器的时间大约是 CentOS、Debian 或 Ubuntu 的 10 倍

标签 docker ubuntu centos signals alpine

我正在使用不同的 Docker 镜像来运行代码并注意到以下内容:

$ time sudo docker stop $(sudo docker run -dit --rm centos:latest)
509285200bcf4ea8389219319b6c4af6554abf9f1c9d9ffb152cd109b6a21453

real    0m1,374s
user    0m0,087s
sys 0m0,027s
$ time sudo docker stop $(sudo docker run -dit --rm debian:latest)
221221b4b9238de633ca68d9539b024c06d015ea503a8b7fd5b827dc903193b8

real    0m1,345s
user    0m0,086s
sys 0m0,034s
$ time sudo docker stop $(sudo docker run -dit --rm ubuntu:latest)
5512fb2505f28f7d2a52788a2ed9775c78ae40805da44e51bb3f22073133f19c

real    0m1,341s
user    0m0,075s
sys 0m0,048s
$ time sudo docker stop $(sudo docker run -dit --rm alpine:latest)
dc1775fa2734c753a5ba6f3fc0b14bf356376d8c701fcf6efa637f1795f41b4a

real    0m11,439s
user    0m0,089s
sys 0m0,032s

如何解释这种差异?

更新:时差完全由docker stop 产生。 .如果我用 docker stop -t 30 延长超时例如,alpine容器占用了所有这些时间并最终超时,而其他容器的行为自然不受超时增加的影响。这似乎与 SIGTERM 的传播有关 - 我可以找到一些以前的问题,但它们大约是 docker stop一般而言,与 alpine 无关明确地。这不能解释为什么 alpine 存在问题。而不是其他图像。

最佳答案

来自 docker stop 的文档:

The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL.



与使用 bash 的 CentOS、Debian 和 Ubuntu 不同, Alpine 使用 busybox sh忽略 SIGTERM并且容器仅在超时后停止 SIGKILL .

这与 bash 的当前版本不同。荣誉SIGTERM并终止。但是,bash 的早期版本确实忽略了SIGTERM ,同样:使用较旧的 CentOS 镜像,如 centos:7也会产生超时。

最后,不清楚为什么bash目前荣誉SIGTERM (见 Why does SIGTERM work to terminate bash but not ash or dash? )或为什么 SIGHUPbusybox sh 工作在 native 系统上,但不使用 docker kill (见 Why does SIGHUP not work on busybox sh in an Alpine Docker container?)。

关于docker - 运行和停止 Alpine Docker 容器的时间大约是 CentOS、Debian 或 Ubuntu 的 10 倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60493765/

相关文章:

phpunit 命令在 ubuntu 16.04 上运行的 lumen 5.6 中不起作用

linux - 将顶级数据导出到文件

docker - 我可以通过暴露的端口停止 docker 容器吗?

jenkins - 用于持续集成/持续部署的 Docker 镜像版本控制

php - 在 apache docker 容器中运行虚拟主机

centos - Centos 7 中的 CPP-REST-SDK

linux - 如何使用存在的符号链接(symbolic link)备份整个服务器?

docker - 如何在Docker容器内交互式运行dotnet核心控制台应用程序

java - bashrc 不识别 java 主目录

c++ - std::regex:Ubuntu(15.10)-Clang++ 生成的二进制文件比 Debian-8-Clang++(均为 v.3.4)性能更高。