pippidis
pippidis

Reputation: 23

Output from Python running on Docker back to host with docker-compose

Im working on a OpenCv project and as many know, the instalation of that on windows is iritating. So, what i want to do is to run the project in a docker container and store the output to a folder on the host computer. In simple terms it is something like this:

  1. Program python / opencv code
  2. Build Docker image
  3. Run Docker image --> Saves the output data somewhere
  4. In some way - get access to the output data on host.

Now, i have been trying to find many ways of dooing this, and i will probably at a later time send it using other means. However, for development i need this slightly more direct approach. It also has somthing to do with colaboration with others.

Simple Docker file that can be used as the base:

FROM python:3
WORKDIR /usr/src/app
COPY . .
CMD [ "python", "./script.py" ]

Lets say that script.py creates a file called output.txt. I want that output.txt stored at my E: drive.

How to do this automatically - without having to do multiple comandline operations?

TLDR; How to get files from Docker container to host? Goal: File physically stored on E:

Upvotes: 0

Views: 1197

Answers (1)

soumith
soumith

Reputation: 616

There are two ways to do this. First is to mount a docker volume.

docker run --name=name -d -v /path/in/host:/path/in/docker name

By mounting a volume like this, whatever you write in the directory you've mounted will be written in the host automatically. Check this for more information on volumes.

The second way is to copy the files from a container to the host like this

docker cp <containerId>:/file/path/within/container /host/path/target

Check docs here for more info on this.

Upvotes: 1

Related Questions