Docker CMD的命令行参数

编程入门 行业动态 更新时间:2024-10-21 11:35:03
本文介绍了Docker CMD的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想将一个参数传入一个停泊点CMD。例如,如果 Dockerfile 的内容是

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 ,给出错误

守护进程错误响应:无法启动容器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/Dockerfile

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

How 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的命令行参数

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

发布评论

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

>www.elefans.com

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