Corrent将参数传递给Docker入口点 [英] Corrent passing arguments to docker entrypoint

查看:73
本文介绍了Corrent将参数传递给Docker入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个超级愚蠢的剧本

I have a super dumb script

$ cat script.sh 
cat <<EOT > entrypoint.sh 
#!/bin/bash
echo "$@"
EOT

docker run -it --rm -v $(pwd)/entrypoint.sh:/root/entrypoint.sh --entrypoint /root/entrypoint.sh bash:4 Hello World

但是当我运行脚本时,出现了奇怪的错误:

But when I run script I got strange error:

$ sh script.sh 
standard_init_linux.go:207: exec user process caused "no such file or directory"

为什么脚本无法打印 Hello world ?

推荐答案

standard_init_linux.go:207: exec user process caused "no such file or directory"

上述错误表示以下情况之一:

The above error means one of:

  • 您的脚本实际上不存在.在您的卷挂载上不太可能发生这种情况,但是在没有入口点的情况下运行容器也不会受到损害,只需打开具有相同卷挂载的外壳并列出文件以确保其存在即可.卷挂载可能在不与Docker VM共享目录的桌面版docker上失败,并且最终在容器内创建空文件夹而不是挂载文件.从另一个容器中进行检查时,还请确保您对该脚本具有执行权限.

  • Your script actually doesn't exist. This isn't likely with your volume mount but it doesn't hurt to run the container without the entrypoint, just open a shell with the same volume mount and list the file to be sure it's there. It's possible for the volume mount to fail on desktop versions of docker where the directory isn't shared to the docker VM and you end up with empty folders being created inside the container instead of mounting your file. When checking from inside of another container, also make sure you have execute permissions on the script.

如果是脚本,则指向解释器的第一行无效.确保该命令存在于容器内.例如.高山容器通常不附带bash,而您需要使用/bin/sh .这是我看到的最常见的问题.

If it's a script, the first line pointing to the interpreter is invalid. Make sure that command exists inside the container. E.g. alpine containers typically do not ship with bash and you need to use /bin/sh instead. This is the most common issue that I see.

如果是脚本,类似于上面的内容,请确保第一行具有linux换行符.Windows换行符会在尝试运行的命令名称中添加和添加 \ r ,这在Linux端找不到.

If it's a script, similar to above, make sure your first line has linux linefeeds. A windows linefeed adds and extra \r to the name of the command trying to be run, which won't be found on the linux side.

如果命令是二进制文件,则可以引用丢失的库.我经常看到这种静态"编译的go二进制文件,这些二进制文件没有禁用CGO,并且在导入网络库时出现了指向libc的链接.

If the command is a binary, it can refer to a missing library. I often see this with "statically" compiled go binaries that didn't have CGO disabled and have links to libc appear when importing networking libraries.

如果您使用json格式运行命令,则我经常会看到此错误,且包含无效的json语法.这不适用于您的用例,但可能对其他使用此问题的人有所帮助.

If you use json formatting to run your command, I often see this error with invalid json syntax. This doesn't apply to your use case, but may be helpful to others googling this issue.

此列表来自我在去年的DockerCon上的演讲:

This list is pulled from a talk I gave at last year's DockerCon: https://sudo-bmitch.github.io/presentations/dc2018/faq-stackoverflow.html#59

这篇关于Corrent将参数传递给Docker入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆