知识卡片

普通读书笔记卡 · 3522.c

Compose用服务名连数据库

理解等级:中级

Compose 声明 API 与数据库两个服务,放在可互通的网络中;API 的连接串用数据库服务名作主机名,而非容器外的 localhost。这种命名把本地联调从手工查容器地址中解耦,前提是两个服务处于同一网络。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 13 章《Dockerizing microservice APIs》(源文件:_epub-src/OEBPS/Text/13.htm) - 结论依据:原文说明 Compose 可让两个容器在共享网络通信,连接串也用 database 作主机名。 - 原始内容:Docker Compose, which allows us to run multiple containers within a shared network, so they can talk to each other. In this section, you’ll learn how to run the orders service with a PostgreSQL database using