一次诡异的docker错误调试

3次阅读

共计 1900 个字符,预计需要花费 5 分钟才能阅读完成。

源自小伙伴的求助,虽然没能定位到最终的原因,调试的过程也比较有意思

缘起

小伙伴求助我,同一个 docker 镜像在测试机器上可以运行,在阿里云上运行提示用户不存在。

在阿里云上运行提示如下:

# docker run --rm -it image:tag
docker: Error response from daemon: linux spec user: unable to find user www-data: no matching entries in passwd file.
ERRO[0000] error waiting for container: context canceled
  • 镜像名称统一使用 image:tag 代替,其实错误和镜像的关系不大
  • 从错误描述看:应该是在 /etc/passwd 中未能找到 www-data 这个用户,判断用户不存在

调试过程

换成用 root 启动,依然提示找不到用户

# docker run --rm -it --user root image:tag
docker: Error response from daemon: linux spec user: unable to find user root: no matching entries in passwd file.
  • 看来 root 也要在 /etc/passwd 里面找

换一种方式启动,错误提示变了

# docker run --rm -it --user $(id -u) image:tag
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"docker-php-entrypoint\": executable file not found in $PATH": unknown.
  • 看来镜像设置有 entrypoint
  • 但是为什么找不到 entrypoint

换一个 entrypoint 试试看

# docker run --rm -it --user $(id -u) --entrypoint'ls' image:tag
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"ls\": executable file not found in $PATH": unknown.
  • ls也找不到?那用 /bin/ls 试试看

# docker run --rm -it --user $(id -u) --entrypoint'/bin/ls' image:tag
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/bin/ls\": stat /bin/ls: no such file or directory": unknown.
  • 这次错误提示换了,找不到/bin/ls
  • 怀疑是文件系统错误,整个 / 下的文件都找不到

/bin/ls 挂载到容器内试试

# docker run --rm -it --user $(id -u) -v'/bin/ls':'/bin/ls'--entrypoint'/bin/ls' image:tag
standard_init_linux.go:190: exec user process caused "no such file or directory"
  • 基本可以确定是 docker 内文件系统挂了

山穷水尽

暂时没找到办法进一步的追踪。通过 docker inspectdocker history均看不出镜像的异常。

通过 docker logs 也看不到容器启动中的其他错误。

柳暗花明

别的小伙伴帮忙找到了这个 issue:Error response from daemon: OCI runtime create failed – when running a Node.js Docker image

虽然错误类型不太一致,发现我一直忘记查看 docker daemon 的日志!!!!

通过 journalctl -fu docker.service 查看错误日志,发现和 issue 中的错误一致。

... level=error msg="stream copy error: reading from a closed fifo"

可能是 docker 的一个未修复的 BUG。

TODO

为何 --user root 时会查找 passwd 文件,--user $(id -u)可以跳过 passwd 文件

正文完
 0