我有以下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","https://www.example.com/main.css"]
下面是我在docker镜像构建后从CMD运行的命令
docker run -it "akamaiapi" //It executes the CMD command as given in above Dockerfile.
CMD [“ node”,“ src / akamai-client.js”,“ purge”,“ https://www.example.com/main.css”] //我希望直接从docker命令传递这两个参数,而不是在Dockerfile中进行硬编码,因此我的Docker运行命令可能是像这些:
docker run -it "akamaiapi" queue
docker run -it "akamaiapi" purge "https://www.example.com/main.css"
docker run -it "akamaiapi" purge-status "b9f80d960602b9f80d960602b9f80d960602"
@H_403_25@
最佳答案@H_403_25@
您可以通过combination of
ENTRYPOINT
and CMD
进行操作.
> ENTRYPOINT
指定在容器启动时将始终执行的命令.
> CMD
指定将输入到ENTRYPOINT的参数.
因此,使用Dockerfile:
FROM node:boron
...
ENTRYPOINT ["node","src/akamai-client.js"]
CMD ["purge","https://www.example.com/main.css"]
正在运行的容器的默认行为:
docker run -it akamaiapi
就像命令:
node src/akamai-client.js purge "https://www.example.com/main.css"
如果您这样做:
docker run -it akamaiapi queue
容器中的基础执行如下:
node src/akamai-client.js queue
@H_403_25@