在docker中从CMD传递参数

编程入门 行业动态 更新时间:2024-10-21 06:31:43
本文介绍了在docker中从CMD传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经了解了Dockerfile。

I have got below Dockerfile.

FROM node:boron # Create app directory RUN mkdir -p /usr/src/akamai WORKDIR /usr/src/akamai # Install app dependencies COPY package.json /usr/src/akamai/ RUN npm install # Bundle app source COPY . /usr/src/akamai #EXPOSE 8080 CMD ["node", "src/akamai-client.js", "purge", "www.example/main.css"]

下面是我在docker映像构建后从CMD运行的命令

Below is the command which I run from CMD after the docker image build

docker run -it "akamaiapi" //It executes the CMD command as given in above Dockerfile.

CMD [ node, src / akamai-client.js,清除 , www.example/main.css ] //我希望直接从docker命令传递这两个参数,而不是在Dockerfile中进行硬编码,因此我的Docker运行命令可能像这样:

CMD ["node", "src/akamai-client.js", "purge", "www.example/main.css"] //I want these two arguments directly passed from docker command instead hard-coded in Dockerfile, so my Docker run commands could be like these:

docker run -it "akamaiapi" queue docker run -it "akamaiapi" purge "www.example/main.css" docker run -it "akamaiapi" purge-status "b9f80d960602b9f80d960602b9f80d960602"

推荐答案

您可以通过组合来实现 ENTRYPOINT 和 CMD 。

You can do that through a combination of ENTRYPOINT and CMD.

  • ENT RYPOINT 指定在容器启动时始终执行的命令。

  • The ENTRYPOINT specifies a command that will always be executed when the container starts.

CMD 指定要馈送到的参数 ENTRYPOINT 。

因此, Dockerfile :

FROM node:boron ... ENTRYPOINT ["node", "src/akamai-client.js"] CMD ["purge", "www.example/main.css"]

正在运行的容器的默认行为:

The default behavior of a running container:

docker run -it akamaiapi

就像命令:

node src/akamai-client.js purge "www.example/main.css"

如果您这样做:

docker run -it akamaiapi queue

包含中的基础执行er将是:

The underlying execution in the container would be like:

node src/akamai-client.js queue

更多推荐

在docker中从CMD传递参数

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

发布评论

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

>www.elefans.com

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