简体   繁体   English

在共享同一网络的两个 docker 容器之间共享数据

[英]Share data between two docker containers sharing same network

I have a requirement to build two applications (in Golang), first application just receives data via UART and send it to the second application for processing, second application should receive the data and process.我需要构建两个应用程序(在 Golang 中),第一个应用程序只是通过 UART 接收数据并将其发送到第二个应用程序进行处理,第二个应用程序应该接收数据并进行处理。

I have already completed receiving data via UART in first application, now I'm looking for better way to get data from first module to second module.我已经在第一个应用程序中完成了通过 UART 接收数据,现在我正在寻找更好的方法来从第一个模块获取数据到第二个模块。 They both are running as docker containers and sharing same docker network.它们都作为 docker 容器运行并共享相同的 docker 网络。

I was thinking of creating rest API in second application and first application will simply send data with http call, but is there a better way to do?我正在考虑在第二个应用程序中创建 rest API 并且第一个应用程序将简单地使用 http 调用发送数据,但是有更好的方法吗? Any other option that can take advantage of docker network?还有其他可以利用 docker 网络的选项吗?

In general, yes sockets are what you need.一般来说,是的 sockets 是您需要的。 Plain TCP/UDP, HTTP server (RESTful API or not), gRPC, etc.普通 TCP/UDP、HTTP 服务器(RESTful API 与否)、gRPC 等。

Or you start another container of a message queue (NATS, Kafka, RabbitMQ, etc), and write pub-sub logic.或者您启动另一个消息队列容器(NATS、Kafka、RabbitMQ 等),并编写发布-订阅逻辑。 Or you can use a database.或者您可以使用数据库。

Or you can mount a shared Docker volume between both containers and communicate via files.或者,您可以在两个容器之间挂载共享的 Docker 卷并通过文件进行通信。

None of these are necessarily unique to Golang and will work with any language.这些都不是 Golang 独有的,并且适用于任何语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM