bash 运行 Docker 交互式 Shell
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46525611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Docker Interactive Shell
提问by Shaurya Chaudhuri
I am trying to run interactive shell for an image which I am running using docker-compose.
我正在尝试为我使用 docker-compose 运行的图像运行交互式 shell。
I tried docker-run and docker-exec
我试过 docker-run 和 docker-exec
xyz@abc:~$ sudo docker exec -it 235197ff4f0e /bin/bash
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:262: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory"
xyz@abc:~$ sudo docker run -it drone/drone:0.7 /bin/bash
No help topic for '/bin/bash'
Trying to generate ssh key inside drone, so that i can clone from private repositories.
尝试在无人机内部生成 ssh 密钥,以便我可以从私有存储库中进行克隆。
回答by larsks
There are several things going on here. I'd like to take a look at the second error first:
这里有几件事情正在发生。我想先看看第二个错误:
The drone/drone
image is configured to automatically run the /drone
command (which you can determine by using docker inspect
and looking for the Entrypoint
key). So if you run:
的drone/drone
图像配置为自动运行/drone
命令(其可以通过使用确定docker inspect
和寻找Entrypoint
键)。所以如果你运行:
docker run drone/drone:0.7 help
You end up running, inside the container:
您最终在容器内运行:
drone help
And of course, if you run:
当然,如果你运行:
docker run drone/drone:0.7 /bin/bash
You are running, in the container:
您正在容器中运行:
drone /bin/bash
Hence the error message you are seeing ("No help topic for '/bin/bash'"), because you are passing an unrecognized option to the the drone
command.
因此,您看到的错误消息(“没有 '/bin/bash' 的帮助主题”),因为您将无法识别的选项传递给drone
命令。
The first error is much simpler. Your error message is:
第一个错误要简单得多。你的错误信息是:
exec: \"/bin/bash\": stat /bin/bash: no such file or directory
That seems pretty clear. There is no /bin/bash
. In fact, if you inspect the contents of the image, you'll see that there is only a minimal filesystem. The easiest way to look is by starting a container, then using docker export
, like this:
这似乎很清楚。没有/bin/bash
。事实上,如果您检查图像的内容,您会发现只有一个最小的文件系统。最简单的查看方法是启动一个容器,然后使用docker export
,如下所示:
$ docker run drone/drone:0.7 help
[...output doesn't matter...]
$ docker export $(docker ps -lq) | tar tf -
Which shows you:
这向您展示了:
.dockerenv
dev/
dev/console
dev/pts/
dev/shm/
drone
etc/
etc/hostname
etc/hosts
etc/mtab
etc/resolv.conf
etc/ssl/
etc/ssl/certs/
etc/ssl/certs/ca-certificates.crt
proc/
sys/
There's no /bin/bash
, no ssh
, no git
, etc, so you're not going to have much luck with your current plan. You may want to consider cloning the remote repositories on your host and then exposing them to your container using a host volume mount (-v /host/path:/container path
), or building a custom image that contains the tooling you need.
没有/bin/bash
,没有ssh
,没有git
等等,所以你目前的计划不会有太多运气。您可能需要考虑在您的主机上克隆远程存储库,然后使用主机卷挂载 ( -v /host/path:/container path
)将它们公开给您的容器,或者构建一个包含您需要的工具的自定义映像。