I have tried to containerize my python code , this is working, building the docker image, running the container and invoking the python code in my app.py file. next, i want to be able to upload the sample.txt file that my python code reads from the root of the application to process some data, sample.txt in the example below. but this file needs to be updated and i want to be able to update this file and run the container, without building the image. how can i create/mount a directory and put the csv file there and give the path to my python code?
app.py
import pandas as pd
print pd.read_csv('sample.csv')
...
docker file
# Dockerfile
FROM debian:10.3-slim
WORKDIR /app
RUN apt-get update && apt-get -y dist-upgrade
RUN apt-get -y install apt-utils
build-essential
python3
gcc
python3-dev
python3-pip
python3-numpy
python3-pandas
COPY requirements.txt /app/requirements.txt
RUN pip3 install -r requirements.txt
# Copy the python script
COPY modbus_to_influx.py /app/modbus_to_influx.py
CMD ["python3", "app.py"]
requirements.txt
numpy
pandas
2
Answers
When you
docker run
, you can (bind) mount folders/files on the host as folders/files on the container:For example if you had
example.csv
on the host’s root directory and you want it to be accessible to your Python app in the container in/data
, you would:Or you can use
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
https://docs.docker.com/engine/reference/commandline/cp/