我想将参数传递给 docker CMD.例如,如果 Dockerfile 的内容是
I want to pass in a parameter into a docker CMD. For example, if the contents of Dockerfile are
FROM ubuntu:15.04 CMD ["/bin/bash", "-c", "cat", "$1"]那我想运行如下:
docker build -t cat_a_file . docker run -v `pwd`:/data cat_a_file /data/Dockerfile我希望将 Dockerfile 的内容打印到屏幕上.但是,Docker 认为 /data/Dockerfile 是一个应该覆盖 CMD 的脚本,从而给出错误
I would like the contents of Dockerfile to be printed to the screen. But instead, Docker thinks that /data/Dockerfile is a script that should override the CMD, giving the error
Error response from daemon: Cannot start container 7cfca4: [8] System error: exec: "/data/Dockerfile": permission denied如何避免这种情况?
推荐答案使用 ENTRYPOINT 来处理这样的事情.任何 CMD 参数都附加到给定的 ENTRYPOINT.
Use ENTRYPOINT for stuff like this. Any CMD parameters are appended to the given ENTRYPOINT.
因此,如果您将 Dockerfile 更新为:
So, if you update the Dockerfile to:
FROM ubuntu:15.04 ENTRYPOINT ["/bin/bash", "-c", "cat"]事情应该如你所愿.
另外,由于您不需要 $1,您应该可以将其更改为:
Also, as you don't need the $1, you should be able to change it to:
FROM ubuntu:15.04 ENTRYPOINT ["/bin/cat"]我还没有测试过这些,所以如果它不起作用,请告诉我.
I haven't tested any of this, so let me know if it doesn't work.
更多推荐
Docker CMD 的命令行参数
发布评论