how to reach another container from a dockerised nginx

前端 未结 1 487
生来不讨喜
生来不讨喜 2021-02-04 10:23

I have nginx in a docker container, and a nodejs webapp in another docker container. The nodejs server is reachable from the host server on port 8080.

The nginx docker c

相关标签:
1条回答
  • 2021-02-04 11:09

    Here's a best practice. Only expose port 80 outside of the host. The nodejs app can be in a private network only accessible through nginx.

    version: "2"
    services:
        nginx:
          ...
          ports:
            - "80:80"
          networks:
            - backbone
        nodejs:
          ...
          networks:
            - backbone
          expose: 
            - 8080
    
    networks:
      backbone:
        driver: bridge
    

    In your nginx.conf file, the upstream servers can be listed as nodejs:8080. The docker daemon will resolve it to the correct internal ip.

    0 讨论(0)
提交回复
热议问题