如何使用docker run命令将json文件作为参数传递 [英] How to pass json file as an argument using docker run command
本文介绍了如何使用docker run命令将json文件作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的Dockerfile内容:
Below is my Dockerfile content:
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
RUN pip install numpy==1.12.0
CMD ["python", "t_1.py", "t_1.json"]
我想在运行时使用docker run命令将此文件(t_1.sjon)作为参数传递,以便CMD [ python , t_1.py,运行时参数]。我尝试挂载卷,但是由于json文件是独立的并且我想作为参数而失败。
I want to pass this file(t_1.sjon) as argument with docker run command at runtime so that CMD ["python", "t_1.py", "RUN TIME ARGUMENT"]. I tried mounting volumes but fails as json file is independent and I want as argument.
请帮助。
推荐答案
您应该使用的是 ENTRYPOINT
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
RUN pip install numpy==1.12.0
ENTRYPOINT ["python", "t_1.py"]
现在,当您运行docker命令时
Now when you run the docker command
docker run -v ./t_1.json:/data/t_1.json <dockerimage> /data/t_1.json
这将使其等效于 python t_1。 py /data/t_1.json
这篇关于如何使用docker run命令将json文件作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文