如何使用 docker run 命令将 json 文件作为参数传递

man*_*oor 2 python file docker

以下是我的 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"]
Run Code Online (Sandbox Code Playgroud)

我想在运行时将此文件(t_1.sjon)作为参数与 docker run 命令一起传递,以便 CMD ["python", "t_1.py", "RUN TIME ARGUMENT"]。我尝试安装卷但失败了,因为 json 文件是独立的,我想作为参数。

请帮忙。

Tar*_*ani 6

你应该使用的是 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"]
Run Code Online (Sandbox Code Playgroud)

现在当你运行 docker 命令时

docker run -v ./t_1.json:/data/t_1.json <dockerimage> /data/t_1.json
Run Code Online (Sandbox Code Playgroud)

这将使其等同于 python t_1.py /data/t_1.json