Reputation: 33
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 ???
My docker-compose file with rails
#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 :
#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
Upvotes: 1
Views: 915
Reputation: 1095
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 (i.e., don't duplicate service names, call them mongo-db and mysql-db or something -- same with the web services).
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/
.
See Hemant's answer for Docker networking documentation.
Upvotes: 0
Reputation: 1608
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.
For more reference, you can refer to https://docs.docker.com/compose/networking/
Communication between multiple docker-compose projects
Upvotes: 1