我有一个Angular
应用程序运行在NginX
Docker
容器。
The Angular
应用程序可以制作一个REST
调用另一个容器(Spring Boot
API Docker
) using localhost
作为服务器。
server: string = 'localhost';
return this.httpClient.post<MyClass[]>('http://' + this.server + ':6060/files-data/list-files', request);
But REST
使用时调用失败Docker
而是服务名称。
server: string = 'files-service';
return this.httpClient.post<MyClass[]>('http://' + this.server + ':8080/files-data/list-files', request);
*这次使用8080端口来尝试解析docker服务名称
UI 控制台中出现错误:
net::ERR_NAME_NOT_RESOLVED
使用默认值NginX
带有默认值的图像nginx.conf
.
nginx-files-ui:
image: nginx:latest
container_name: nginx-files-ui
volumes:
- ./files-ui/dist/html:/usr/share/nginx/html
ports:
- 99:80
容器都在同一个上运行Docker
网络。
networks:
default:
external:
name: files-net
修改的nginx.conf
包括解析器但没有乐趣。
resolver 127.0.0.11 valid=30s;
知道为什么我不能做一个REST
呼叫使用Docker
服务名称 ?
EDIT
浏览器中运行的 Angular 代码似乎无法解析服务名称。
Docker compose服务无法通过服务名称进行通信 https://stackoverflow.com/questions/44412367/docker-composed-services-cant-communicate-by-service-name