通过UNIX套接字在Docker容器之间进行连接 [英] Connection between docker containers via UNIX sockets

查看:639
本文介绍了通过UNIX套接字在Docker容器之间进行连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,但我想知道:是否可以通过UNIX套接字将Linux机器(任何)上的另一个容器与另一个容器相连?
例如,我有一个用于应用程序核心的容器,另一个有用于覆盖数据库内容的容器。
第二个示例是两个带有应用程序代码的容器,第一个容器可以在第二个容器中触发一些事件。

I’m newbie to Docker, but i’d like to know: is it possible to connect one container from another container on Linux machine (any) with UNIX sockets? For example i have one container for application core and second containers which covers database things. Second example is two containers with application code, and first container can trigger some events in second.

在我看来,性能对我来说都很重要。
如果不可能通过这种方式解决这些问题,那么有解决方案吗?

Performance really matters for me in both cases. If it’s impossible to do this way, is there is any solution for these problems?

谢谢!

推荐答案

是。您可以使用批量安装将套接字安装到容器中。而且,多个容器可以挂载相同的卷(无论是命名卷还是主机挂载),以在容器之间共享套接字。您今天在挂载Docker套接字的容器中经常看到这种情况,例如

Yes. You can mount a socket into a container using a volume mount. And multiple containers can mount the same volume, whether that's a named volume or a host mount, to share the socket between the containers. You see this frequently with containers that mount the docker socket today, e.g.

docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock busybox

将运行带有

关于docker.sock本身的说明:

Notes on the docker.sock itself:


  1. 上面是安装套接字的示例,将docker.sock替换为您自己的应用程序套接字的名称。

  2. 是的,上面给出了容器访问权限以管理docker,有效地根植于主机上。您将看到用于管理打包为容器的docker的工具。您可以通过服务器上的root用户访问权限来隐式信任它们,这与信任主机上通过apt或rpm下载的代码不同。选择性地授予您访问权限。

这篇关于通过UNIX套接字在Docker容器之间进行连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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