如何将Docker-ubuntu容器启动到bash中? [英] How do you start a Docker-ubuntu container into bash?

查看:320
本文介绍了如何将Docker-ubuntu容器启动到bash中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的答案无效。

在我可以附加或不接受-之前,docker容器总是退出t 标志。我可以列出我尝试过的所有命令,但这是 start exec 使用各种 -it 标志和 / bin / bash 附加。

The docker container always exits before I can attach or won't accept the -t flag. I could list all of the commands I've tried, but it's a combination of start exec attach with various -it flags and /bin/bash.

如何将现有容器启动为bash?为什么这么难?这是对Docker的不当使用吗?

How do I start an existing container into bash? Why is this so difficult? Is this an "improper" use of Docker?

编辑:
我用 docker run ubuntu 。有关容器的信息: 60b93bda690f ubuntu / bin / bash大约一个小时前退出(0)50分钟前ecstatic_euclid

EDITS: I created the container with docker run ubuntu. The information about the container: 60b93bda690f ubuntu "/bin/bash" About an hour ago Exited (0) 50 minutes ago ecstatic_euclid

推荐答案

首先,容器不是虚拟机。容器是用于运行进程的隔离环境。容器的生命周期与内部运行的进程绑定在一起。当进程退出时,容器也退出,隔离环境也消失了。 附加到容器或输入容器的含义实际上意味着您进入了正在运行的进程的隔离环境,因此,如果您的进程已退出,则您的容器也已退出,因此没有容器供您附加输入。因此, docker attach docker exec 的命令的目标是运行容器。

First of all, a container is not a virtual machine. A container is an isolation environment for running a process. The life-cycle of the container is bound to the process running inside it. When the process exits, the container also exits, and the isolation environment is gone. The meaning of "attach to container" or "enter an container" actually means you go inside the isolation environment of the running process, so if your process has been exited, your container has also been exited, thus there's no container for you to attach or enter. So the command of docker attach, docker exec are target at running container.

Dockerfile docker run 后,将启动哪个进程$ c>并内置到docker映像中。以图像 ubuntu 为例,如果运行 docker inspect ubuntu ,则会在输出中找到以下配置:

Which process will be started when you docker run is configured in a Dockerfile and built into a docker image. Take image ubuntu as an example, if you run docker inspect ubuntu, you'll find the following configs in the output:

"Cmd": ["/bin/bash"]

这意味着当您运行 docker run ubuntu 时该进程已启动, / bin / bash ,但是您没有处于交互模式,也没有为它分配tty,因此该过程立即退出,容器退出。这就是为什么您无法再次输入容器的原因。

which means the process got started when you run docker run ubuntu is /bin/bash, but you're not in an interactive mode and does not allocate a tty to it, so the process exited immediately and the container exited. That's why you have no way to enter the container again.

要启动容器并输入 bash ,只需尝试:

To start a container and enter bash, just try:

docker run -it ubuntu

然后将您带入容器外壳。如果打开另一个终端并 docker ps ,您会发现该容器正在运行,您可以 docker附加 docker exec -it< container_id> bash 再次输入。

Then you'll be brought into the container shell. If you open another terminal and docker ps, you'll find the container is running and you can docker attach to it or docker exec -it <container_id> bash to enter it again.

您还可以参考此链接以获取更多信息。

You can also refer to this link for more info.

这篇关于如何将Docker-ubuntu容器启动到bash中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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