如何进入已经使用新 TTY 运行的 Docker 容器 [英] How to enter in a Docker container already running with a new TTY

查看:69
本文介绍了如何进入已经使用新 TTY 运行的 Docker 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在前台运行 Apache 服务的容器.我希望能够从另一个 shell 访问容器,以便在它内部探查"并检查文件.目前,如果我附加到容器,我只能查看 Apache 守护程序并且无法运行任何命令.

I have a container that is running the Apache service in the foreground. I would like to be able to access the container from another shell in order to "poke around" inside it and examine the files. At the moment, if I attach to the container, I am left looking at the Apache daemon and cannot run any commands.

是否可以将另一个 tty 附加到正在运行的容器?也许,我可以利用 Docker 实际上只是围绕 LXC 容器这一事实?我已经尝试过 sudo lxc-console -n [container-id] -t [1-4] 但似乎只有一个 tty 可用,并且是运行 apache 守护进程的那个.也许有一种方法可以在构建过程中启用多个 lxc 控制台?

Is it possible to attach another tty to a running container? Possibly, I can take advantage of the fact that Docker is actually just wrapping around LXC containers? I have tried sudo lxc-console -n [container-id] -t [1-4] but it appears that only one tty is made available and that is the one running the apache daemon. Perhaps there is a way to enable multiple lxc consoles during the build?

如果可能,我宁愿使用 openssh 服务配置和构建容器.

I would rather not configure and build the container with an openssh service if possible.

推荐答案

在 docker 1.3 中,有一个新命令 docker exec.这允许您进入正在运行的容器:

With docker 1.3, there is a new command docker exec. This allows you to enter a running container:

docker exec -it [container-id] bash

注意:这假设 bash 已安装在您的容器上.您可以运行 sh 或容器上安装的任何交互式 shell.

Note: this assumes bash is installed on your container. You may run sh or whatever interactive shell is installed on the container.

这篇关于如何进入已经使用新 TTY 运行的 Docker 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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