简体   繁体   English

如何在 docker 容器中运行 /bin/bash?

[英]How to run /bin/bash in a docker container?

How to run /bin/bash in a docker container that was started with the -d option , for example:如何在使用-d option启动的 docker 容器中运行/bin/bash ,例如:

sudo docker run -P --name test-cnt3 -d base-tst:0.1? 

I really need a console in the container and I already despaired of running it我真的需要容器中的控制台,但我已经对运行它感到绝望

使用docker exec在已经运行的容器中运行命令,使用-it创建一个新的交互式伪 TTY:

docker exec -it test-cnt3 /bin/bash

If you use docker-composer or Dockerfile look at Entrypoint & CMD如果您使用 docker-composer 或 Dockerfile,请查看Entrypoint & CMD

And to connect use sudo docker attach awesome-container并连接使用sudo docker attach awesome-container

In my case, docker exec -it test /bin/bash gave me就我而言, docker exec -it test /bin/bash给了我

Error response from daemon: Container f63bba8... is not running

When I tried当我尝试

docker start test

the container started, but trying exec again threw the same error as before.容器启动了,但再次尝试 exec 会抛出与以前相同的错误。

In the end, I had to enter最后,我不得不进入

docker run -it test /bin/bash

This starts the bash right before the container stops.这会在容器停止之前启动 bash。

docker exec -it container-name /bin/bash

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

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