Docker 容器-通信
我有一个关于 docker 镜像、容器的问题。
我制作了 2 张图像:一张来自我的前端 UI,另一张来自 Rest-api(模拟服务器)。 Rest-api 有一个 UI 正在监视的提供端口。如果我从 docker 运行rest-api 容器,然后 npm start
Visual Studio 代码中的 UI 就可以工作,在本地主机上我可以看到带有模拟数据的 UI。 如果我在浏览器中打开请求 404 Not Found,让我们停止此 localhost UI 运行并启动 UI 容器。它似乎无法访问或什至无法观看模拟服务器端口。 我不确定我做错了什么或如何正确地做。
对于未来的计划,我希望实现拥有一个包含真实数据的后端容器和数据库,并将 UI 容器连接到这些容器,这样当我在 UI 上工作时,我可以轻松地构建一个包含 UI 更改的新图像,并使用真实的后端数据不是模拟数据。
现在我想连接到模拟来看看它至少能工作。
如果从 VS Code 运行,前端 UI 默认为 localhost:3000,并且它侦听作为模拟服务器的 localhost:2107 端口。 我从那里有 Docker Desktop,我可以运行这两个容器,但似乎这两个容器无法相互通信。如果我只运行模拟服务器容器和从代码编辑器本地启动的 UI,它就可以工作,我也不必从代码编辑器启动模拟服务器。我的本地 UI 选择了 docker 容器模拟服务器 2107 端口。 当我尝试对 UI 容器执行相同操作时,在浏览器中打开它,它会给出错误组件,即未处理的 API 屏幕。所以 UI 容器运行得也很好,只是似乎没有监听 2107 模拟 api 端口。
I have a question regarding docker images, containers.
I made 2 images: 1 from my Frontend UI and another from Rest-api(mock server).
Rest-api has an offered port that UI is watching. If I run the rest-api container from docker then npm start
the UI in visual studio code it works, on localhost I can see the UI with the mock data.
Lets stop this localhost UI run and start the UI container, if I open in the browser the request 404 Not Found. It seems like it can't access or not even watching the mock-server port.
I am not sure what I done wrong or how to do it properly.
For future plan I'd like to achieve to have a backend container and db with the real data and connect the UI container to those, so as I work on the UI I can easily build a new images with the UI changes and check them with real backend data not mock data.
For now I'd like to connect to the mock to see it work at least.
Frontend UI if runs from VS Code it is by default localhost:3000 and it listens to the localhost:2107 port which is the mock-server.
I have Docker Desktop from there I can run both container, but it seems the 2 container can't communicate with each other. If I only run the mock server container and the UI I start locally from my code editor it works, I don't have to start the mock server from code editor as well. My local UI picks up the docker container mock server 2107 port.
When I try to do the same with the UI container, run it open in the browser it gives the error component which is an Unhandled API screen. So UI container runs as well it just doesn't seem to listen to the 2107 mock api port.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论