ruby on rails - Running different docker containers on same host/different port -
i have app composed of multiple rails projects, trying dockerize them, each app starts on different rails port :
- main app: 1665
- admin: 3002
- website: 3000
- ...
this docker-compose.yml file :
version: '2' services: db: image: postgres:9.6 container_name: acme_db hostname: db.myapp.dev hostname: db.ach ports: - "5432:5432" volumes: - myapp_pgdata:/var/lib/postgresql/data/pgdata environment: - pgdata=/var/lib/postgresql/data/pgdata - virtual_host=db.myapp.dev networks: - generic myapp: image: acme/myapp container_name: acme_myapp hostname: app.myapp.dev command: rails s -p 1665 -b '0.0.0.0' volumes: - ./myapp:/usr/src/app - $ssh_auth_sock:/tmp/ssh_auth_sock ports: - "1665:1665" depends_on: - db environment: - ssh_auth_sock=/tmp/ssh_auth_sock - rails_env=development - virtual_host=myapp.dev networks: - generic admin: image: acme/admin container_name: acme_admin hostname: admin2.myapp.dev command: rails s -p 3002 -b '0.0.0.0' volumes: - ./admin2:/usr/src/app - $ssh_auth_sock:/tmp/ssh_auth_sock ports: - "3002:3002" depends_on: - myapp environment: - ssh_auth_sock=/tmp/ssh_auth_sock - rails_env=development - virtual_host=admin2.myapp.dev networks: - generic website: image: acme/website container_name: acme_website hostname: web.myapp.dev command: rails s -p 3001 -b '0.0.0.0' volumes: - ./website:/usr/src/app - $ssh_auth_sock:/tmp/ssh_auth_sock ports: - "3001:3001" environment: - ssh_auth_sock=/tmp/ssh_auth_sock - rails_env=development - virtual_host=myapp.dev networks: - generic volumes: myapp_pgdata: external: true networks: generic: external: true
running each app works fine, have problem when applications need communicate between them, instance website need forward http request main app, , when does, tries resolve uri: http://app.myapp.dev:1665/register
and, resolved ip 127.0.0.1 instead of myapp
docker container ip.
how can manage situation ? should use different hostnames each container ? ideally avoid dns resolution rails tries hit app.myapp.dev:1665
instead of resolving app.myapp.dev
, resolving 127.0.0.1:1665
btw, using jwilder/nginx-proxy
resolve containers hostnames laptop.
any thoughts ?
your setup allows containers resolve each other names through 'network' set docker-compose.
so website
should able hit main app through http://myapp:1665/register
Comments
Post a Comment