Pass arguments to Python argparse within Docker container

前端 未结 3 1781
春和景丽
春和景丽 2020-12-28 08:42

I am embarking on my first attempt at utilizing a docker container. I have a python script that calls a couple API\'s and parses a file. The script took parameters for the

3条回答
  •  清酒与你
    2020-12-28 09:29

    So let's assume your command is below

    python app.py "URL" "APIKEY" "filepath"
    

    So you will put your Dockerfile in below fashion

    FROM python:3.6
    WORKDIR /app
    COPY app.py .
    ENTRYPOINT ["python", "app.py"]
    

    Then the person running the docker container would do it like below

    docker run -v /home/tarun/project/filetoparse.yaml:/config.yaml  "URL" "APIKEY" /config.yaml
    

    If you want to give more flexibility you an can even use environment variables

    docker run -v /home/tarun/project/filetoparse.yaml:/config.yaml -e APIKEY="XYZ"  "URL" /config.yaml
    

    And then in your script you can read it using os.environ['APIKEY']

提交回复
热议问题