源自小夥伴的求助,雖然沒能定位到最終的原因,調試的過程也比較有意思
緣起
小夥伴求助我,同一個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 inspect
和docker 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
文件