https://docs.docker.com/engine/reference/builder/#cmd在 Dockerfile 中这样说
CMD ["executable","param1","param2"]
是“执行形式”并且
CMD command param1 param2
是“shell 形式”,它们的运行方式略有不同。
Note: Unlike the shell form, the exec form does not invoke a command shell
但是当您使用 docker run 传递命令时,我可以找到任何方法让它在没有命令 shell 的情况下运行。
docker run container-name echo test # shell form I guess
什么是执行形式?
最佳答案
为什么要猜测?检查一下。
docker run ubuntu sh -c 'echo "Hello world!"'
创建一个可以使用docker container ls -a
发现的容器
并通过id进行检查。
检查命令显示,除了显式的之外,没有添加额外的 sh -c:
"Cmd": [
"sh",
"-c",
"echo \"Hello world!\""
],
因此当前的假设是它使用exec 形式。
只是提一下:我对 docker-compose run 的测试显示了相同的结果。
docker 的记录都非常少。和 docker-compose , 这是真的。 --entrypoint
选项稍微幸运一些,记录在 dockerfile docs :
You can override the ENTRYPOINT setting using --entrypoint, but this can only set the binary to exec (no sh -c will be used).
关于docker - 使用 docker run 在 'exec form' 中传递命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46430844/