Edward
Edward

Reputation: 4623

Save docker output file in workdir

I am a newby in docker My Dockerfile

FROM python:3
WORKDIR /app
COPY . /app
RUN pip install numpy
RUN pip install pandas
CMD ["python", "app.py"]

And in app.py I have a line

pd.DataFrame(predictions, columns=['predictions']).to_csv('output.csv')

I build and run the image, that's ok but I can not to save this dataframe in my work directory. How to change Dockerfile so that I can do it?

Upvotes: 1

Views: 773

Answers (1)

bellackn
bellackn

Reputation: 2174

Probably the best way to get output.csv out of the container onto your host machine is using a volume. Volumes are storage paths that can be shared between host and container, much like shared folders for VMs.

In your case:

docker run --rm -v $(pwd)/volume:/app your_image

You should then find everything from the container's /app path in your working directory under ./volume.

Upvotes: 2

Related Questions