多个项目使用同一网络的 Docker DNS [英] Docker DNS with Multiple Projects Using the Same Network

查看:26
本文介绍了多个项目使用同一网络的 Docker DNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 docker-compose.yml 文件:

version: '3'
services:
    frontend:
        image: alpine
        command: tail -f /dev/null
        networks:
            - shared
            - default
    backend:
        image: alpine
        command: tail -f /dev/null
        networks:
            - shared
            - default
networks:
    shared:
        external: true

基于上面的文件,我创建了两个项目,它们使用相同的网络(shared)和相同的服务名称(frontendbackend>):

Based on the file from above I create two projects which use the same network (shared) and the same service names (frontend and backend):

docker-compose -p foo up -d
docker-compose -p bar up -d

docker 的 DNS 是否确保 docker-compose -p foo exec frontend ping backend 只解析到项目 foo 中的后端容器,反之亦然项目 <代码>条形?

Does the DNS of docker make sure that docker-compose -p foo exec frontend ping backend only resolves to the backend container in project foo and vice versa for project bar?

推荐答案

根据 https://github.com/docker/compose/issues/4645,这种情况下的解析顺序是不确定的.由于网络在 golang 中正在转换为无序 dict,因此不会保留顺序.这意味着 https://github.com/docker/libnetwork/blob/master/sandbox.go#L593 被查询端点的顺序与网络顺序不匹配.

According to https://github.com/docker/compose/issues/4645, the resolve order in this case in non deterministic. Since the network is being converted to unordered dict in golang, the order is not preserved. Which implies https://github.com/docker/libnetwork/blob/master/sandbox.go#L593 the order of endpoints being queried don't match the order of network.

解决办法是定义https://docs.docker.com/compose/compose-file/compose-file-v2/#priority 如果使用 docker-compose 版本 2.或者完全限定的 dns 名称为 service.networkbackend.foo_defaultbackend.shared.

The solution is to define https://docs.docker.com/compose/compose-file/compose-file-v2/#priority if using docker-compose version 2. Or fully qualified dns name as service.network such as backend.foo_default or backend.shared.

这篇关于多个项目使用同一网络的 Docker DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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