How to access CSV file (located in pc hdd) from a docker container with python pandas?

前端 未结 1 1279
礼貌的吻别
礼貌的吻别 2021-01-16 06:48

I want to implement a Machine Learning algorithm which can operate on homomorphic data using PySEAL library. PySEAL library is released as a docker container with an \'examp

相关标签:
1条回答
  • 2021-01-16 07:33

    You can either do it via the Docker build process (assuming you are the one creating the image) or through a volume mapping that would be accessed by the container during runtime.

    Building source with Dataset.csv within

    For access through the build, you could do a Docker Copy command to get the file within the workspace of the container

    FROM 3.7
    
    COPY /Dataset.csv /app/Dataset.csv
    ...
    

    Then you can directly access the file via /app/Dataset.csv from the container using pandas.read_csv() function, like -

    data=pandas.read_csv('/app/Dataset.csv')
    

    Mapping volume share for Dataset.csv

    If you don't have direct control over the source image creation, or do not want the dataset packaged with the container (which may be the best practice depending on the use case). You can share it through a volume mapping when starting the container:

    dataset = pd.read_csv ('app/Dataset.csv')
    

    Assuming your Dataset.csv is in my/user/dir/Dataset.csv

    From CLI:

    docker run -v my/user/dir:app my-python-container
    

    The benefit of the latter solution is you can then continue to edit the file 'Dataset.csv' on your host and the file will reflect changes made by you OR the python process should that occur.

    0 讨论(0)
提交回复
热议问题