然后我想运行如下:
docker build -t cat_a_file。 docker run -v`pwd`:/ data cat_a_file / data / Dockerfile我会像 Dockerfile 的内容要打印到屏幕。但是,Docker认为, / data / Dockerfile 是一个脚本,应该覆盖 CMD ,给出错误
守护进程错误响应:无法启动容器7cfca4: [8]系统错误:exec:/ data / Dockerfile :permission denied
如何避免这种情况?
解决方案使用 ENTRYPOINT 这样的东西。任何 CMD 参数附加到给定的 ENTRYPOINT 。
所以,如果您将Dockerfile更新为:
FROM ubuntu:15.04 ENTRYPOINT [/ bin / bash ,-c,cat]事情应该符合你的要求。
另外,由于您不需要 $ 1 ,您应该可以将其更改为:
FROM ubuntu:15.04 ENTRYPOINT [/ bin / cat]我没有测试任何这个,所以让我知道,如果它不工作。
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"]Then I want to run as follows:
docker build -t cat_a_file . docker run -v `pwd`:/data cat_a_file /data/DockerfileI 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 deniedHow can this be avoided?
解决方案Use ENTRYPOINT for stuff like this. Any CMD parameters are appended to the given ENTRYPOINT.
So, if you update the Dockerfile to:
FROM ubuntu:15.04 ENTRYPOINT ["/bin/bash", "-c", "cat"]Things should work as you wish.
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的命令行参数
发布评论