dangyuluo
V2EX  ›  Docker

Docker 容器内的 sleep 无法被中断么?

  •  
  •   dangyuluo · Jan 6, 2023 · 1978 views
    This topic created in 1419 days ago, the information mentioned may be changed or developed.

    sleep 10 不能被中断,但是ping www.google.com却可以。请问有什么讲究么?

    docker run -it --rm nicolaka/netshoot sleep 10
    docker run -it --rm nicolaka/netshoot ping www.google.com
    
    5 replies  •  2023-01-06 11:38:05 +08:00
    xzysaber
    xzysaber
    Jan 6, 2023
    2
    信号处理的问题。
    有时候还可以注意一下镜像的 Dockerfile 是否使用了 STOPSIGNAL 指令。当然所有的最终都是信号处理的问题。
    57L49t45Jo9IJvge
    57L49t45Jo9IJvge
    Jan 6, 2023
    3
    感谢 op 这个问题挺有趣
    Trim21
    Trim21
    Jan 6, 2023
    4
    进程忽略信号就可能杀不掉。可以用 --init 参数,docker 会在容器内额外起一个 tini 进程确保信号被处理。
    dangyuluo
    dangyuluo
    OP
    Jan 6, 2023
    5
    @Trim21 应该是 sleep 没有捕获 SIGINT ,而 ping 为了在结尾显示 min/avg/max 等信息捕获了 SIGINT 。--init 确实好使
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1004 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:10 · PVG 06:10 · LAX 14:10 · JFK 17:10
    ♥ Do have faith in what you're doing.