Reputation: 3052
I an trying to create a development environment with multiple microservices running like in a production environment.
I would like to run with Docker two rails applications
that makes calls between them.
I know that I can use links
, but with this I always has to run one of them as the master one. That means, that I only can debug this one, and I would like to see the console ouput of each of them. Maybe I am doing something wrong, and that's why I am asking.
This is my docker-compose.yml file:
rails-app-A:
build: .
dockerfile: "DockerfileA"
environment:
RAILS_ENV: development
links:
- db
command: bundle exec rails server -p 3005 -b '0.0.0.0'
volumes:
- ".:/home/app"
volumes_from:
- bundle
expose:
- "3005"
ports:
- "3005:3005"
rails-app-B:
build: .
dockerfile: "DockerfileB"
environment:
RAILS_ENV: development
links:
- db
command: bundle exec rails server -p 3000 -b '0.0.0.0'
volumes:
- ".:/home/app"
volumes_from:
- bundle
expose:
- "3000"
ports:
- "3000:3000"
This is how I run the rails app:
docker-compose run --service-ports rails-app-A
docker-compose run --service-ports rails-app-B
I always get errors like these:
Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 3000
Errno::ECONNREFUSED (Failed to open TCP connection to localhost:3000 (Connection refused - connect(2) for "localhost" port 3000))
The thing is that I can access to all of them with the browser.
With the Docker version for OSX using VirtualBox this was working fine (just calling localhost:3000
or localhost:3005
), but in Ubuntu or with Docker-beta, is failing.
I understand that "localhost" for rails-app-A is a different server as "localhost" in rails-app-B, because they run as different machines. When I had VirtualBox
I could access because I had the IP of the VirtualBox instance (192.169.99.100).
I am now using http://localtunnel.me/
and I can access to the other services. But, anyway, Is there a better way to do this?
Upvotes: 3
Views: 1341
Reputation: 3052
Finally, I achieve to call external services using an external_link
:
rails-app-A:
build: .
dockerfile: "DockerfileA"
environment:
RAILS_ENV: development
links:
- db
external_links:
- app_B
...ommited lines...
app_B
should be a running container, previously executed like this:
docker-compose run --service-ports --name app_B rails-app-B
Adding this --name app_B
makes it accessible using this name.
What I still don't understand is how to build
rails-app-A without previously open rails-app-B. If rails-app-A has rails-app-B as external link and the same happens in the other direction, builds
become unmanageable.
Upvotes: 1