我已经了解了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传递参数
发布评论