连接到正在运行的docker容器 - 使用ssh和运行带有“-t -i”的命令之间的差异参数 [英] Connecting to a running docker container - differences between using ssh and running a command with "-t -i" parameters

查看:268
本文介绍了连接到正在运行的docker容器 - 使用ssh和运行带有“-t -i”的命令之间的差异参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能指点一下安装openssh-server和启动ssh会话与给定的docker容器有什么区别,并运行 docker运行-t -i ubuntu / bin / bash 然后执行一些操作。

解决方案

差异1如果要使用ssh,则需要在Docker映像上安装ssh并在容器上运行。您可能不想因为额外的负载或从安全角度。一种方法是保持尽可能小的图像 - 避免错误,如令人失望的;)。无论你想要ssh是一个讨论点,但主要是个人品味。我会说只用于调试,而不是实际改变你的图像。如果你需要后者,你最好做一个新的和更好的形象。个人来说,我还没有在Docker镜像上安装我的第一个ssh服务器。



区别2.使用ssh可以根据CMD指定启动您的容器,也可以启动ENTRYPOINT你的Docker文件。然后,Ssh允许您检查该容器并运行命令,以了解您可能需要的任何用例。另一方面,如果您使用bash命令启动容器,则可以有效地覆盖Dockerfile CMD。如果您要测试该CMD,您仍然可以手动运行它(可能作为后台进程)。调试我的图像时,我一直都这样做。这是从发展的角度来看的。



差异3.第二个扩展,但从不同的角度来看。在生产中,ssh将始终允许您检出运行的容器。 Docker在这方面有其他有用的选项,例如 docker cp docker logs ,确实 docker附加



根据文档附加命令将允许您查看或与任何正在运行的容器进行交互,分离(-d)或交互式(-i)。您可以同时附加到同一容器 - 屏幕共享风格,或快速查看您的守护进程的进度。但是,在实际使用这个方面我遇到麻烦。也许使用它的人可以详细阐述?



这些是唯一的根本区别。图像层,提交或类似的任何内容都没有区别。


Could you please point me what is the difference between installing openssh-server and starting a ssh session with a given docker container and running docker run -t -i ubuntu /bin/bash and then performing some operations. How does docker attach compare to those two methods?

解决方案

Difference 1. If you want to use ssh, you need to have ssh installed on the Docker image and running on your container. You might not want to because of extra load or from a security perspective. One way to go is to keep your images as small as possible - avoids bugs like heartbleed ;). Whether you want ssh is a point of discussion, but mostly personal taste. I would say only use it for debugging, and not to actually change your image. If you would need the latter, you'd better make a new and better image. Personally, I have yet to install my first ssh server on a Docker image.

Difference 2. Using ssh you can start your container as specified by the CMD and maybe ENTRYPOINT in your Dockerfile. Ssh then allows you to inspect that container and run commands for whatever use case you might need. On the other hand, if you start your container with the bash command, you effectively overwrite your Dockerfile CMD. If you then want to test that CMD, you can still run it manually (probably as a background process). When debugging my images, I do that all the time. This is from a development point of view.

Difference 3. An extension of the 2nd, but from a different point of view. In production, ssh will always allow you to check out your running container. Docker has other options useful in this respect, like docker cp, docker logs and indeed docker attach.

According to the docs "The attach command will allow you to view or interact with any running container, detached (-d) or interactive (-i). You can attach to the same container at the same time - screen sharing style, or quickly view the progress of your daemonized process." However, I am having trouble in actually using this in a useful manner. Maybe someone who uses it could elaborate in that?

Those are the only essential differences. There is no difference for image layers, committing or anything like that.

这篇关于连接到正在运行的docker容器 - 使用ssh和运行带有“-t -i”的命令之间的差异参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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