【发布时间】:2019-02-02 09:53:41
【问题描述】:
我有两个链接的 Docker 容器 api 和 frontend。 frontend 是 nginx 容器内的 ReactJS 应用程序。这是 Dockerfile:
FROM nginx:alpine
COPY ./build /usr/share/nginx/html/
和运行命令:
docker run --name frontend --link api:api -p 80:80 frontend_img
当我 sh 在 frontend 中运行时:
$ wget http://api:8080/api/users
工作正常,我可以获取用户。但是,当我的应用尝试获取数据时,我在 Chrome 控制台中收到 ERR_NAME_NOT_RESOLVED 错误。
这是我的 JS 代码:
fetchUsers() {
return axios.get('http://api:8080/api/users')
.then(response => response.data)
.then(users => this.setState({ users }));
}
我错过了什么?我是否需要在 NGINX 中配置一些东西才能从api 或其他东西中获取数据?
【问题讨论】:
标签: reactjs http docker nginx wget