是否可以在 docker 容器之间共享内存? [英] Is it possible to share memory between docker containers?
问题描述
我处理一个具有不同进程的应用程序,我被要求包含这些进程以实现更多隔离.
问题在于进程与单个管理程序"进程共享内存以交换数据(它们使用经典共享缓冲区).这个方案是为了性能需求而实现的,因为它运行在用户空间,所以没有用户空间和内核空间之间的内容切换.
如果我没记错的话,在单个 IPC 命名空间中运行多个 docker 容器是不可能的,但是我不知道单个 docker 容器是否可能属于不同的 IPC 命名空间,这可以解决我的问题问题.
欢迎使用其他解决方案,但请记住,性能是一项要求,提前致谢.
--ipc=host
和 --ipc=container:id
选项已被添加到 Docker create
和 run
命令来共享 IPC 资源.
--ipc="";: 设置容器的IPC模式,'container:':重用另一个容器的 IPC 命名空间'host':在容器内使用主机的 IPC 命名空间
IPC 与主机
docker run --ipc=host
IPC 与另一个容器
docker run --ipc=container:<图像>
IPC 与另一个容器可能需要在初始容器上设置 shareable
选项(如果 dockerd 默认 IPC 为 private
)
docker run --ipc=shareable
I work on an application with different processes and I'm asked to contain those processes for achieving more isolation.
The problem is that the processes share memory with a single "hypervisor" process in order to exchange data (they use classic shared buffers). This solution was implemented for performance requirement and because it is running in user-space, so there aren't content switching between user-space and kernel-space.
If I'm not wrong is not possible to run more than one docker container inside a single IPC namespace, but I don't know if it is possible that a single docker container belongs to different IPC namespaces, this could solve my problem.
Other solutions are welcome, just keep in mind that performance is a requirement, thanks in advance.
The --ipc=host
and --ipc=container:id
options have since been added to the Docker create
and run
commands to share IPC resources.
--ipc="" : Set the IPC mode for the container, 'container:<name|id>': reuses another container's IPC namespace 'host': use the host's IPC namespace inside the container
IPC with the host
docker run --ipc=host <image>
IPC with another container
docker run --ipc=container:<id> <image>
IPC with another container may need the shareable
option set on the initial container (if dockerd defaults IPC to private
)
docker run --ipc=shareable <image>
这篇关于是否可以在 docker 容器之间共享内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!