1

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?

2
  • What do you want to achieve exactly? Do you need the output on your host machine? Or is output.csv not being created in /app at all? Commented May 1, 2019 at 15:46
  • I need the output on my host machine. The file is created Commented May 1, 2019 at 15:47

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

It looks like /app is not empty, from to the COPY instruction in the Dockerfile. The original contents of /app would get hidden when the volume is mounted this way. Using any other path to mount the volume instead of /app should be fine in this case.
@Proyag can I delete COPY or change WORKDIR in Dockerfile?
I agree, @Proyag. @Edward, you could change your Python code to save your CSV somewhere else, e.g. /home/your_user/output.csv. Then you would change the volume definition to -v $(pwd)/volume:/home/your_user.
I use docker run --rm -v $(pwd)/volume:/e/test my_image It works but the output is not saved. If I channge in app.py `to_csv('/e/test/output.csv') I get error
No such file or directory
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.