Docker 将参数传递给使用 argparse 的 python 脚本
Docker pass in arguments to python script that uses argparse
我有以下 docker 图片
FROM ubuntu
RUN apt-get update \
&& apt-get install -y python3 \
&& apt-get install -y python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install boto3
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY /src/* $INSTALL_PATH/src/
ENTRYPOINT python3 src/main.py
在我的 python 脚本中,入口点也指向我有一些我想传递的参数。我在我的 python 脚本中使用 argparse 来构造它们。示例是 --key 作为 arg 选项。这个 --key 参数将在脚本的每个 运行 上改变。如何将此参数传递到我的脚本中,以便它以正确的参数执行?
我试过了
docker 运行 my_image_name --key 100
但参数没有到达 python 脚本。
您可以使用 CMD 命令传递参数(并为入口点设置默认值),例如:
CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]
查看here了解详情。
我有以下 docker 图片
FROM ubuntu
RUN apt-get update \
&& apt-get install -y python3 \
&& apt-get install -y python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install boto3
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY /src/* $INSTALL_PATH/src/
ENTRYPOINT python3 src/main.py
在我的 python 脚本中,入口点也指向我有一些我想传递的参数。我在我的 python 脚本中使用 argparse 来构造它们。示例是 --key 作为 arg 选项。这个 --key 参数将在脚本的每个 运行 上改变。如何将此参数传递到我的脚本中,以便它以正确的参数执行?
我试过了 docker 运行 my_image_name --key 100
但参数没有到达 python 脚本。
您可以使用 CMD 命令传递参数(并为入口点设置默认值),例如:
CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]
查看here了解详情。