Docker CMD 的命令行参数

编程入门 行业动态 更新时间:2024-10-21 04:15:42
本文介绍了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 的命令行参数

本文发布于:2023-11-17 04:49:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608891.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   参数   Docker   CMD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!