0

First off, I might have formulated the question inaccurately, feel free to modify if necessary.

Although I am quite new to docker and all its stuff, yet somehow managed to create an image (v2) and a container (cont) on my Win 11 laptop. And I have a demo.py which requires an .mp4 file as an arg.

Now, if I want to run the demo.py file, 1) I go to the project's folder (where demo.py lives), 2) open cmd and 3) run: docker start -i cont. This starts the container as:

root:834b2342e24c:/project#

Then, I should copy 4) my_video.mp4 from local project folder to container's project/data folder (with another cmd) as follows:

docker cp data/my_video.mp4 cont:project/data/.

Then I run: 5) python demo.py data/my_video.mp4. After a while, it makes two files: my_video_demo.mp4 and my_video.json in the data folder in the container. Similarly, I should copy them back to my local project folder: 6)

docker cp cont:project/data/my_video_demo.mp4 data/, docker cp cont:project/data/my_video_demo.json data/

Only then I can go to my local project/data folder and inspect the files. I want to be able to just run a particular command that does 4) - 6) all in one. I have read about -v option where, in my case, it would be(?) -v /data:project/data, but I don't know how to proceed.

Is it possible to do what I want? If everything is clear, I hope to get your support. Thank you.

2
  • Docker probably isn't the right tool for what you're describing, since a container doesn't usually have access to files outside the container. Can you use a Python virtual environment instead? Commented Jan 20, 2022 at 12:23
  • I'd love to, but demo.py requires dependencies that are of Linux, not Windows. I tried building the project on Windows, but failed spectacularly :D. Commented Jan 20, 2022 at 23:27

2 Answers 2

0

You should indeed use Docker volumes. The following command should do it.

docker run -it -v /data:project/data v2
Sign up to request clarification or add additional context in comments.

1 Comment

1. Where does it run the demo.py file? 2. Where are the output files get created?
0

Well, I think I've come up with a way of dealing with it.

I have learned that with -v one can create a place that is shared between the local host and the container. All you need to do is that run the docker and provide -v as follows:

docker run --gpus all -it -v C:/Workspace/project/data:/project/data v2:latest python demo.py data/my_video_demo.mp4

--gpus - GPU devices to add to the container ('all' to pass all GPUs);

-it - tells the docker that it should open an interactive container instance.

Note that every time you run this, it will create a new container because of -it flag.

Partial credit to @bill27

Comments

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.