passing file to docker command

2019-05-25 22:23发布

问题:

I am attempting to run opencv through docker container. I have built the image and while running the container directly

docker run -v /home/ganaraj/nndetect:/detect -ti opecv3 bash

and accessing the bash

$>cd /detect/prediction $>prediction 1.jpg 0

I do get the output I am expecting ( the final 0 ).

But I would actually wish to run this as a command line program.

I have tried both

docker run -v /home/ganaraj/nndetect:/detect -ti opecv3 /detect/prediction/prediction 1.png

docker run -v /home/ganaraj/nndetect:/detect -ti opecv3 /detect/prediction/prediction /detect/prediction/1.png

But both of these dont provide me the output I am expecting from this.

What would be the right way to do this, so that I can run this app easily like a command line tool ( through docker ) and get the output back ?

I have also tried

docker run -v /home/ganaraj/nndetect:/detect -it -d opecv3 bin/bash

and then :

docker exec -it 3d618d63316c /detect/prediction/prediction /detect/prediction/1.png

but still I get the same blank response.

Client:
 Version:      1.8.3
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f4bf5c7
 Built:        Mon Oct 12 05:37:18 UTC 2015
 OS/Arch:      linux/amd64

Server:
 Version:      1.8.3
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f4bf5c7
 Built:        Mon Oct 12 05:37:18 UTC 2015
 OS/Arch:      linux/amd64

回答1:

docker exec is mainly for debugging purpose.

The primary use case of docker exec is debugging running containers,
docker exec basically is for "exceptional" cases

When you want to execute a command (here a python program), it is best to run a container just for that command.

alias dr='docker run -v /home/ganaraj/nndetect:/detect -w /detect/prediction -it --rm opecv3'

That way, without having python installed on your host, you could use determined_rosalind simply by typing:

dr ./prediction 1.png

That would launch a transient container to run the python program, exit and be removed (--rm option).



回答2:

I finally got it working - but I am not sure "why" this makes it work.. If someone has an explanation for why please add it too..

But I thought it might be a good idea to post the final solution here..

I started the container with the following command :

docker run -v /home/ganaraj/nndetect:/detect -w /detect/prediction -it -d opecv3 bash

And now I can make the prediction with this command and it works fine

docker exec -it determined_rosalind ./prediction 1.png