简体   繁体   English

将 Apollo 客户端和 Apollo 服务器与 Docker 一起使用

[英]Using Apollo Client and Apollo Server with Docker

Here's a riddle.这里有个谜语。

I have two containers running in Docker.我有两个容器在 Docker 中运行。 One holds a create-react-app client using Apollo Client.一个拥有一个使用 Apollo 客户端的 create-react-app 客户端。 The other container is a Node.js Apollo Server.另一个容器是 Node.js Apollo 服务器。 The client is able to connect to the server without issue when I use the external IP and the Apollo server's port.当我使用外部 IP 和 Apollo 服务器的端口时,客户端能够毫无问题地连接到服务器。 However, when I try to use the Docker network, I get ERR_NAME_NOT_RESOLVED on the client side when connecting to the server.但是,当我尝试使用 Docker 网络时,我在连接到服务器时在客户端收到 ERR_NAME_NOT_RESOLVED。

What could be wrong?有什么问题?

Here's the docker-compose.yml这是 docker-compose.yml

version: "3"
services:
        mornai:
                image: mornai
                container_name: mornai
                ports:
                        - 5000:5000
                volumes:
                        - mornaidata1:/usr/mornai/data
        mornai-web:
                image: mornai-client
                ports:
                        - 3000:3000
                depends_on:
                        - mornai
                environment:
                        REACT_APP_APOLLO_URL: "mornai"
                volumes:
                        - mornaiwebdata1:/usr/mornai-web/data
volumes:
        mornaidata1:
                driver: local
        mornaiwebdata1:
                driver: local

The Apollo client is using the following uri: http://mornai:5000/ Apollo 客户端使用以下 uri: http://mornai:5000/

The Apollo server (mornai) is definitely listening on port 5000 Apollo 服务器(mornai)肯定在监听 5000 端口

Docker-compose is definitely creating a default network with two containers, and when I inspect the network I see the 'mornai' service listed Docker-compose 肯定是在创建一个包含两个容器的默认网络,当我检查网络时,我看到列出了“mornai”服务

Answer: The browser can't access internal Docker networks.答:浏览器无法访问内部 Docker 网络。 - @DavidMaze - @大卫迷宫

Well that's obvious in hindsight and I'm feeling pretty silly.事后看来,这很明显,我觉得很傻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM