docker - 什么是 Docker 附加?

标签 docker

我对 Docker 很陌生,我已经能够理解 4 件事

  • Dockerfile
  • Docker 镜像
  • Docker 容器
  • docker 撰写

以及一些基本命令,如 docker run、docker log 等。

现在,我遇到了这个命令 docker attach,这里有描述

Use docker attach to attach to a running container using the container’s ID or name, either to view its ongoing output or to control it interactively. You can attach to the same contained process multiple times simultaneously, screen sharing style, or quickly view the progress of your detached process.`

我不知道他们说如果我们想查看容器的正在进行的事件或输出,我们可以附加是什么意思?如果我有一个用于控制台应用程序的容器并且我只是这样做 docker run 然后我可以在控制台窗口中看到输出。

docker attach 有哪些好处?

最佳答案

当容器使用交互选项运行时,您可以连接到容器并像在终端上一样输入命令:

$ docker run -itd --name busybox busybox
dcaecf3335f9142e8c70a2ae05a386395b49d610be345b3a12d2961fccab1478

$ docker attach busybox
/ # echo hello world
hello world

attach 选项还允许多个连接查看同一个容器并查看每个连接的内容。

最后,当使用 tty 选项 (-t) 连接到容器时,您可以键入 Control-P Control -Q 从该容器中分离并使其在后台运行。然后,您可以在以后再次附加到该容器。

关于docker - 什么是 Docker 附加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44347397/

相关文章:

Docker:创建的文件在层之间消失

mongodb - 无法连接到docker容器中的mongodb

node.js - Docker 不缓存 npm 安装

python - 使用Shell脚本在python Shell中运行命令的意外行为

javascript - 无法从 Docker 容器内部连接到 Redis 集群

elasticsearch - 使用 Elasticsearch 2.1 自己构建的 Docker 容器的权限问题

linux - J 安装错误 : Cannot Find "libedit.so"

docker - 为什么 "sh -c command"中的 -c 在某些情况下是强制性的,而在其他情况下是不允许的?

docker - Google Cloud Run | Angular项目部署为无服务器容器COPY失败:未指定源文件

docker - 如何在 Windows 上的 Docker 中启动 nginx