Launch a separate Rails App with docker-compose. Here, only the settings in docker-compose are written.
I want to make API communication between Rails apps launched locally with different docker-compose. e.g. I want to hit the Rails App2 API of the image diagram from Rails App1
I'll leave it so that you can get to this memo from the keywords.
Errno::ECONNREFUSED: Connection refused - connect(2)
--docker network create --driver bridge common_link
--docker network ls
(confirm the created network)
--Define networks:
in the services hierarchy of docker-compose.yml for Rails App1 and Rails App2
docker-compose.yml
services:
.
.
networks:
common_link:
external: true
--Define networks
in each container setting location of Rails App1, DB1, Rails App2, DB2
services:
rails_app1:
networks:
- common_link
db1:
networks:
- common_link
--Modified docker-compose.yml to avoid overlapping MySQL port of docker-compose2 with 3306
services:
db2:
ports:
- "127.0.0.1:3307:3307"
--If there is a setting to bind MySQL in Rails App2 of docker-compose2, change the port value as well.
services:
rails_app2:
environment:
DATABASE_URL: mysql2://root:root@mysql:3307
--Specify port in MySQL config of docker-compose2 e.g. /Dockerfiles/mysql/conf.d/mysql.cnf
[client]
port=3307
[mysqld]
port=3307
--Start both docker-compose1 and docker-compose2
--docker network inspect common_link
(Confirmation that a total of 4 containers of Rails App1, DB1, Rails App2, DB2 belong to the same network)
e.g. Containers
--If it doesn't seem to be a problem, try ping, curl, or hit the API.
ping 172.19.0.5
# If the IP (172.19.0.5) confirmed in the above temporary image is set to rails_app2curl 172.19.0.5
Please let me know if there are other good settings.
https://qiita.com/reneice/items/20e981062b093264cd0a