在运行docker image时将url作为参数传递给python

我想在运行docker映像时传递GCP存储URL作为参数,以便它可以从存储中提取我的csv文件并打印数据集。

下面是我的dockerfile

import subprocess

command='im extractattachments[issue=10378365,overwriteExisting=confirm]'
process=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
(out,err) = process.communicate()

我尝试通过以下命令运行docker映像并获得以下错误

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM continuumio/miniconda3


# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip install flask gunicorn
RUN pip install scikit-learn==0.20.2 firefly-python==0.1.15
RUN pip install --upgrade google-cloud-storage
ENTRYPOINT ["python"]
CMD ["pre.py"]

docker run preprocess:v1 "https://storage.googleapis.com/MYBucket/app/Model/IrisClassifier.sav"
python: can't open file 'https://storage.googleapis.com/MYBucket/app/Model/IrisClassifier.sav': [Errno 2] No such file or directory

我想在运行docker映像时传递类似的GCP存储桶 https://storage.googleapis.com/MYBucket/app/Model/IrisClassifier.sav

charlesluo326 回答:在运行docker image时将url作为参数传递给python

首先需要将所有CMD更改为ENTRYPOINT

FROM continuumio/miniconda3

ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

RUN pip install Flask gunicorn
RUN pip install scikit-learn==0.20.2 firefly-python==0.1.15
RUN pip install --upgrade google-cloud-storage
ENTRYPOINT ["python","pre.py"]

然后您可以通过URL

设置的问题是:

docker将启动入口点,即python,并使用您的命令覆盖CMD夹将为您提供

python YOUR_URL

更新

我不知道您是否添加了if语句来运行主要def,但是在这里您应该如何编辑脚本:

def main():
    print("Prior to entering arg")
    parse_arguments()


if __name__ == '__main__':
    main()
本文链接:https://www.f2er.com/3168731.html

大家都在问