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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答