[英]How to pass json file as an argument using docker run command
Below is my Dockerfile content: 以下是我的Dockerfile内容:
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"]
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"]. 我想在运行时使用docker run命令将此文件(t_1.sjon)作为参数传递,以便CMD [“ python”,“ t_1.py”,“ RUN TIME ARGUMENT”]。 I tried mounting volumes but fails as json file is independent and I want as argument.
我尝试挂载卷,但由于json文件是独立的,因此我想作为参数失败。
Please help. 请帮忙。
What you should use is ENTRYPOINT
您应该使用
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"]
Now when you run the docker command 现在,当您运行docker命令时
docker run -v ./t_1.json:/data/t_1.json <dockerimage> /data/t_1.json
This will make it equivalent to python t_1.py /data/t_1.json
这将使其等同于
python t_1.py /data/t_1.json
You can use bash to run any command inside docker container. 您可以使用bash在docker容器中运行任何命令。
docker run <your_image> bash -c "python /app/t_1.json"
I am assuming that the json file is in the directory where you are having the dockerfile. 我假设json文件位于您拥有dockerfile的目录中。 So it being copied inside the container at
/app
, can be run using the bash command inside container. 因此,它可以在
/app
的容器内复制,可以使用容器内的bash命令运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.