【问题标题】:Detect whether docker socket inside a container belongs to the docker daemon running inside it or is injected from the container host检测容器内的 docker socket 是属于运行在其中的 docker daemon 还是从容器主机注入的
【发布时间】:2020-03-24 11:47:08
【问题描述】:

我正在寻找一种可靠的方法来检测是否使用-v参数(@ 987654323@)或由在 docker 容器内运行的 docker 守护进程创建(在 docker 容器的入口点运行 dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375)。

我想强调我想在容器内而不是在主机上检查这个。

我首选的解决方案是可以在容器内执行的 shell 脚本。输出可能是一个字符串,例如“docker-in-docker”或“injected-socket”(取决于检测到的模式)。

【问题讨论】:

    标签: docker


    【解决方案1】:

    我找到了以下用于检查卷是否安装在容器内的解决方案:Docker - check within the container if a directory is mounted from the host or not

    以下脚本适用于 alpine 和 debian 容器:

    #!/bin/sh
    
    v=$(mount | grep "/run/docker.sock")
    
    if [ -n "$v" ]; then
      echo "injected-socket"
    elif [ -S /var/run/docker.sock ]; then
      echo "local-socket"
    else
      echo "no-socket"
      exit 1
    fi
    

    其他参考资料:

    检查空命令输出 https://stackoverflow.com/a/37618542/4202031

    识别套接字文件的存在 https://stackoverflow.com/a/12137503/4202031

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-11
      • 2022-10-04
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 2017-11-19
      相关资源
      最近更新 更多