简体   繁体   English

连接在docker-compose上分别运行的两个应用程序

[英]connect two application running separatly on docker-compose

I have a django application with mysql (chatbot) and rails application with mongodb each run over docker-compose They both running separately I want to connect them together, how can i accomplish that ??? 我有一个带有mysql(chatbot)的django应用程序和一个带有mongodb的rails应用程序,每个应用程序都在docker-compose上运行。它们都单独运行,我想将它们连接在一起,我该怎么实现?

My docker-compose file with rails 我的带有docker的docker-compose文件

#with rails on the dockerfile
version: '3.6'
services:
  db:
    image: mongo:latest
    volumes:
      - ./tmp/db:/var/lib/mongo/data
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/IMS
    ports:
      - "3000:3000"
    depends_on:
      - db
  bundle:
    image: ims_web
    volumes:
      - /bundle

The django prroject : django prroject:

#with django on the dockerfile
version: '3.6'
services:
  db:
    image: mysql:latest
    volumes:
      - ./tmp/db:/var/lib/mysql/data
  web:
    build: .
    command: bundle exec rails s -p 4000 -b '0.0.0.0'
    volumes:
      - .:/SDV
    ports:
      - "4000:4000"
    depends_on:
      - db
  bundle:
    image: sdv_web
    volumes:
      - /bundle

You just need to make sure that the containers you want to talk to each other are on the same network. 您只需要确保要互相交谈的容器在同一网络上即可。 You need to create a custom network in your docker compose files. 您需要在docker compose文件中创建一个自定义网络。

For more reference, you can refer to https://docs.docker.com/compose/networking/ 有关更多参考,您可以参考https://docs.docker.com/compose/networking/

Communication between multiple docker-compose projects 多个docker-compose项目之间的通信

If these applications are meant to be run together, I would suggest combining your docker-compose files here and identifying each service with a unique name (ie, don't duplicate service names, call them mongo-db and mysql-db or something -- same with the web services). 如果打算将这些应用程序一起运行,我建议在这里合并您的docker-compose文件,并用唯一的名称标识每个服务(即,不要重复使用服务名称,将它们称为mongo-db和mysql-db之类的东西- -与网络服务相同)。

At that point, so long as all of your services share a common network, you will be able to intercommunicate by using the service name as hostname. 届时,只要您所有的服务共享一个公共网络,就可以使用服务名作为主机名进行相互通信。 For example, you can hit your new rails-web service from django-web via http://rails-web/ . 例如,您可以通过http://rails-web/django-web新的rails-web服务。

See Hemant's answer for Docker networking documentation. 有关Docker网络文档,请参阅Hemant的答案。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM