dockerfile中的运行命令中没有网络

发布于 2025-02-03 01:19:06 字数 948 浏览 0 评论 0原文

我不知道如何提出更好的要求,但是我有2个单独目录中的2个docker-compose.yml文件。我已经使用网络外部将它们连接起来,并使用服务名称作为主机名,在运行时工作正常(cmd node test.js),但是当我使用运行时,无法工作节点test.js(我获取错误:GetAddrinfo eai_again后端在使用该地址获取时错误)

这是我的代码:

# backend/docker-compose.yml

services:
    backend:
        container_name: backend
        networks:
          - my-network

networks:
    my-network:
# front/docker-compose.yml

services:
    front:
        container_name: front
        build:
            context: .
            args:
              - BACKEND_URL=http://backend:1337
        networks:
          - backend_my-network
        depends_on:
          - backend

networks:
    backend_my-network:
        external: true

这就是我构建它们的方式:

docker-compose up -d --build

I don't know how to ask better but I have 2 docker-compose.yml files in 2 separate directories. I've connected them with networks external and using service's name as hostname which works fine during runtime (CMD node test.js) but not working when I use RUN node test.js (I get Error: getaddrinfo EAI_AGAIN backend error while fetching with that address)

this is my code:

# backend/docker-compose.yml

services:
    backend:
        container_name: backend
        networks:
          - my-network

networks:
    my-network:
# front/docker-compose.yml

services:
    front:
        container_name: front
        build:
            context: .
            args:
              - BACKEND_URL=http://backend:1337
        networks:
          - backend_my-network
        depends_on:
          - backend

networks:
    backend_my-network:
        external: true

and this is how I build them:

docker-compose up -d --build

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文