Docker CMD 的命令行参数 [英] Command line arguments to Docker CMD

查看:44
本文介绍了Docker CMD 的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将参数传递给 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 的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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