将文件传递给docker命令 [英] passing file to docker command

查看:173
本文介绍了将文件传递给docker命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过docker容器运行opencv.我已经构建了图像并在直接运行容器时

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

并访问bash

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

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

我确实得到了期望的输出(最后的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.

我都尝试过

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.

什么是正确的方法,这样我就可以像命令行工具一样轻松地运行此应用程序(通过docker)并返回输出?

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 ?

我也尝试过

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

然后:

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

推荐答案

docker exec是主要用于调试目的.

docker exec is mainly for debugging purpose.

docker exec的主要用例是调试正在运行的容器,
docker exec基本上是针对特殊"情况的

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

当您要执行命令(这里是python程序)时,最好只为该命令运行一个容器.

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'

这样,无需在主机上安装python,您只需输入以下内容即可使用determined_rosalind:

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

dr ./prediction 1.png

这将启动 瞬变 容器,运行python程序,退出并被删除(--rm选项).

这篇关于将文件传递给docker命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆