码头附件和码头处理器之间的区别 [英] difference between docker attach and docker exec

查看:110
本文介绍了码头附件和码头处理器之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者都能够在容器中执行命令。
两者都可以分离容器。

Both will be able to execute commands in container. Both could detach the container.

那么docker exec和docker之间的真正区别是什么?

So what is the real difference between docker exec and docker attach?

推荐答案

有一个提交PR ,添加到文档中:

There was a commit PR which added to the doc:


注意:此命令( attach )不用于在容器中运行新进程。
请参阅: docker exec

Note: This command (attach) is not for running a new process in a container. See: docker exec.

Docker。在运行的容器( run -d )中获取bash\ssh?说明了区别:

The answer to "Docker. How to get bash\ssh inside runned container (run -d)?" illustrates the difference:

(docker> = 1.3)如果我们使用 docker attach 我们只能使用一个shell实例

所以如果我们要打开新的终端新的容器外壳的实例,我们只需要运行 docker exec

(docker >= 1.3) If we use docker attach, we can use only one instance of shell.
So if we want open new terminal with new instance of container's shell, we just need run docker exec

如果docker容器是使用 / bin / bash 命令启动的,可以使用attach访问它,如果没有,则需要执行使用 exec 在容器内创建一个bash实例的命令。

if the docker container was started using /bin/bash command, you can access it using attach, if not then you need to execute the command to create a bash instance inside the container using exec.

此问题



  • Attach不是在容器中运行一个额外的东西,它用于附加到正在运行的进程。

  • docker exec 专门用于在已经启动的容器中运行新的东西,无论是外壳还是其他进程。

  • Attach isn't for running an extra thing in a container, it's for attaching to the running process.
  • "docker exec" is specifically for running new things in a already started container, be it a shell or some other process.

同样的问题补充说:


虽然 attach 没有很好的命名,特别是因为LXC命令 lxc-attach (这更像是 docker exec< container> / bin / sh ,但LXC具体),它确实具有一个特定的目的,可以将您附加到Docker启动的进程。

根据进程的行为可能会有所不同,例如附加到 / bin / bash 会给你一个shell,但是附加到redis-server将像你刚刚启动redis直接而不进行后台管理。

While attach is not well named, particularly because of the LXC command lxc-attach (which is more akin docker exec <container> /bin/sh, but LXC specific), it does have a specific purpose of literally attaching you to the process Docker started.
Depending on what the process is the behavior may be different, for instance attaching to /bin/bash will give you a shell, but attaching to redis-server will be like you'd just started redis directly without daemonizing.

这篇关于码头附件和码头处理器之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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