dockerfile中的运行命令中没有网络
我不知道如何提出更好的要求,但是我有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论