【问题标题】:How do i pass arguments to a python script in a container如何将参数传递给容器中的 python 脚本
【发布时间】:2022-11-04 02:05:38
【问题描述】:

我的 python 脚本需要两个参数来运行 --manual、--ckl 和一个可选的 --output。 manual 和 ckl 只是用于创建输出文件的文件。我在脚本中使用 argparse。

当我尝试运行docker run test --manual test.xml --ckl rhel7.ckl

我收到这个错误

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "--manual": executable file not found in $PATH: unknown.
FROM python:3.10
WORKDIR /home/johnb
RUN pip install pandas 
ADD manual_into_ckl.py .
#command to run 
CMD [ "python", "manual_into_ckl.py"]

我是新手,我不确定如何正确配置 dockerfile。我尝试在 docker run 命令中使用完整路径,但这并没有改变任何东西

【问题讨论】:

    标签: docker dockerfile


    【解决方案1】:

    如果您希望将参数传递给容器,请在exec form 中使用 ENTRYPOINT 指令,而不是在 Dockerfile 中使用 CMD。

    FROM python:3.10
    WORKDIR /home/johnb
    RUN pip install pandas 
    ADD manual_into_ckl.py .
    #command to run 
    ENTRYPOINT [ "python", "manual_into_ckl.py"]
    

    然后将容器运行为

    docker run test --manual test.xml --ckl rhel7.ckl
    

    传递给docker run 的附加参数将作为参数传递给 dockerfile 中指定的入口点。结果命令看起来像

    python manual_into_ckl.py --manual test.xml --ckl rhel7.ckl
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-26
      • 1970-01-01
      • 2012-08-23
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      • 2012-12-29
      相关资源
      最近更新 更多