简体   繁体   English

了解 docker 构成 django 的端口接线,反应 app 和 haproxy

[英]Understanding docker compose port wiring for django, react app and haproxy

I came across a docker-compose.yml which has following port configuration:我遇到了一个 docker-compose.yml ,它具有以下端口配置:

    wsgi: 
        ports: 
            - 9090  // ?? Is it by default mapped to host port 80 ??  

    nodejs 
            image: nodejs:myapp 
            ports: 
                - 9999:9999 
            environment: 
                BACKEND_API_URL: http://aa.bb.cc.dd:9854/api/ 

    haproxy 
        ports: 
            - 9854:80        

I am trying to understand how the port wiring is happening here.我试图了解端口接线是如何在这里发生的。

nodejs UI app settings needs to specify backend port which is 9854 here. nodejs UI 应用设置需要在这里指定后端端口,即9854 This port is exposed by haproxy setting and is mapped to port 80 .此端口由haproxy设置公开并映射到端口80 I know that wsgi is a django backend app.我知道wsgi是一个 django 后端应用程序。 From its entrypoint.sh (in PS below) and port specification in above docker-compose.yml , I get that django listens to port 9090 .从它的entrypoint.sh (在下面的 PS 中)和上面docker-compose.yml中的端口规范,我知道 django 监听端口9090 But I am unable to get how this port 9090 maps to port 80 (which is then exposed by haproxy at 9854 , which in turn is specified in BACKEND_API_URL by nodejs settings).但是我无法了解此端口9090如何映射到端口80 (然后由haproxy9854公开,而这又由nodejs设置在BACKEND_API_URL中指定)。

PS: PS:

Django wsgi app has following in \wsgi\entrypoint.sh : Django wsgi 应用程序在\wsgi\entrypoint.sh中有以下内容:

    nohup gunicorn myapp.wsgi --bind "0.0.0.0:9090" 

And nodejs react app has following in its server.js file: nodejs react app 在其server.js文件中有以下内容:

    const port = process.env.PORT || 9999; 

On your host, there are three ports visible:在您的主机上,可以看到三个端口:

  1. http://aa.bb.cc.dd:9854 forwards to port 80 on the haproxy container. http://aa.bb.cc.dd:9854转发到haproxy容器上的 80 端口。
  2. http://aa.bb.cc.dd:9999 forwards to port 9999 on the nodejs container. http://aa.bb.cc.dd:9999转发到nodejs容器上的 9999 端口。
  3. The port shown by docker-compose port wsgi 9090 forwards to port 9090 on the wsgi container. docker-compose port wsgi 9090显示的端口转发到wsgi容器上的端口 9090。

You don't discuss the HAProxy configuration at all, but it is presumably configured to listen on port 80, and that may be the missing bit of configuration you're looking for.您根本没有讨论 HAProxy 配置,但它可能配置为侦听端口 80,这可能是您正在寻找的配置中缺少的部分。

Between these three containers (so not visible to your front-end application), assuming you don't have any networks: blocks in the Compose file, there are three obvious URLs: http://haproxy:80 (or just http://haproxy ), http://nodejs:9999 , and http://wsgi:9090 connect to their respective containers.在这三个容器之间(因此对您的前端应用程序不可见),假设您没有任何networks:在 Compose 文件中的块,有三个明显的 URL: http://haproxy:80 (或只是http://haproxy )、 http://nodejs:9999http://wsgi:9090连接到各自的容器。 Note that these use the "normal" ports for their service, and not the remapped port for haproxy or the randomly-chosen port for wsgi .请注意,它们使用“普通”端口进行服务,而不是haproxy的重新映射端口或wsgi的随机选择端口。

I'm guessing the HAProxy container is configured to do some sort of path-based routing to one or the other of the other containers.我猜 HAProxy 容器被配置为对其他容器中的一个或另一个进行某种基于路径的路由。 If you have this setup, you might be able to configure your React application to not include a host name in the URL at all ( BACKEND_API_URL: /api/ ), which will make it easier to deploy.如果你有这个设置,你也许可以将你的 React 应用程序配置为在 URL 中完全不包含主机名( BACKEND_API_URL: /api/ ),这将更容易部署。 You do not need the ports: for connections between containers, and if you don't want a caller to be able to reach the back-end services without going via the proxy, you can delete their ports: blocks.您不需要ports:用于容器之间的连接,并且如果您不希望调用者能够在不通过代理的情况下访问后端服务,您可以删除它们的ports:块。

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

相关问题 React 应用程序集代理不适用于 docker compose - React app set proxy not working with docker compose Docker 与反应应用程序组成网络问题 - Docker compose networking issue with react app docker撰写django和节点 - docker compose django and node 在 docker-compose 中没有启动带有 craco 的 React App - React App with craco doesn't start in docker-compose Docker 撰写未正确复制文件以运行反应应用程序 - Docker compose not properly copying files to run react app Docker Compose 与 Docker 工具箱:Node、Mongo、React。 React 应用程序未显示在所述地址中 - Docker Compose with Docker Toolbox: Node, Mongo, React. React app not showing in the said adress 使用 docker-compose 构建应用程序时,如何在 React 应用程序中为 URL 端点使用 Docker 容器名称? - How to use Docker container name for URL endpoint in React app when building app with docker-compose? docker-compose使用的端口如何稳定? - How to stabilize the port used by docker-compose? 运行 React 应用程序的 docker 容器在哪个端口? Reacts 的默认端口或来自 Dockerfile 的 EXPOSE? - On what PORT is my docker container with a React app running? Reacts' default PORT or EXPOSE from Dockerfile? 如何在 docker-compose 中制作 React 应用程序? 构建步骤完成后容器正在退出 - How do I make a react app in docker-compose? Container is exiting after build steps are complete
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM