douan2907 2019-03-02 10:13
浏览 170
已采纳

如何获得两个运行Flask服务和Golang服务的Docker容器互相通信?

I have a flask service running through docker-compose on port 5000. Similarly, I have a different go service running through another docker-compose on port 8000. The Golang service needs to call a flask API running on 5000. I am facing trouble in getting the go service to call flask service. I have tried adding docker-network but failed. What are the pros and cons of running both the services through different docker-compose as compared to single docker-compose? (I have not been able to successfully run them in a single docker-compose, btw). docker ps running both the containers.

Flask Docker compose

version: '3'  # version of compose format

services:
  bidders:
    build:
      dockerfile: Dockerfile
      context: .
    volumes:
      - .:/usr/src/bidders # mount point
    ports:
      - 5000:5000  # host:container

Go Docker Compose

version: '3'

services:
  auctions:
    container_name: auctions
    build: .
    command: go run main.go
    volumes:
      - .:/go/src/auctions
    working_dir: /go/src/auctions
    ports:  
      - "8000:8000"

Third Nwtwork Docker-compose.yml

#docker-compose.yml
version: '3'

networks:
    - second_network

networks:
  second_network:
    driver: bridge
  • 写回答

1条回答 默认 最新

  • dsuoedtom207012191 2019-03-02 10:19
    关注

    With a single docker-compose.yml it will be easier to make both services inside the same network. So what was the issue you got while doing this ? Also make sure that your flask and go application both are binding to 0.0.0.0 from the code itself and not 127.0.0.1 so you can reach them from outside the container.

    With two docker-compose.yml you have two options:

    • Create a network through one of these files and make the other container which in another file join this external network.

    • Create a network using docker network create and define an external network in both files for your containers

    There is a similar question that you can check it's answer from here with example included

    You can check Networking in Compose for more information

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器