简体   繁体   English

运行Docker Interactive Shell

[英]Running Docker Interactive Shell

I am trying to run interactive shell for an image which I am running using docker-compose. 我正在尝试为使用docker-compose运行的图像运行交互式外壳。

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密钥,以便我可以从专用存储库中克隆。

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). drone/drone图像配置为自动运行/drone命令(您可以通过使用Entrypoint docker inspect和寻找Entrypoint密钥来确定)。 So if you run: 因此,如果您运行:

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 . 没有/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: 最简单的查看方法是启动一个容器,然后使用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. 没有/bin/bash ,没有ssh ,没有git等,因此您当前的计划不会有太多的运气。 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. 您可能要考虑克隆主机上的远程存储库,然后使用主机卷挂载( -v /host/path:/container path )将它们公开到容器中,或者构建包含所需工具的自定义映像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM