ruby on rails - How two docker containers communicate each other? -


i've 2 containers , want communicate each other. container 'a' consist discourse.org application postgresql database on port 5432, container 'b' has ror application running on port 1000. want make database connection ror app postgresql(which in container). how connect ror app postgresql database?

ror application, docker-compose.yml

version: '2' services:   app:     build: .     command: bundle exec rails s -p 9000 -b '0.0.0.0'     volumes:       - ".:/slackcron"     ports:       - "9000:9000" 

ror application, database.yml

development:   <<: *default   database: discourse   username: muzammil   password: '123'   host: 0.0.0.0   port: 5432 

docker ps

container id        image                 command                  created             status              ports                                                                names 92a9cb961e56        slackcroncom_app      "bundle exec rails..."   47 seconds ago      46 seconds       0.0.0.0:9000->9000/tcp                                               slackcroncom_app_1 b727c2d0d5ba        local_discourse/app   "/sbin/boot"             10 minutes ago      10 minutes       0.0.0.0:443->443/tcp, 0.0.0.0:5432->5432/tcp, 0.0.0.0:8080->80/tcp   app 

firstly, can try set discourse in multi-container mode: https://github.com/discourse/discourse_docker#single-container-vs-multiple-container after than, may have single docker-compse.yml file struct: app, db (discourse database) , discourse_app.

secondly, can try run postgresql outside using expose operator. add app.yml:

expose:  ...   - "5432:5432" # postgresql ports 

you must have password postgres user: enter container:

su - postgres psql -d postgres -c "alter user postgres password '<new password>';" 

also can try use docker networking, this:

$ docker network ls  network id          name                driver 7fca4eb8c647        bridge              bridge 9f904ee27bf5        none                null cf03ee007fb4        <discourse_name>    host 

you see network discourse container. can try use application.

version: '2' services:   app:     build: .     command: bundle exec rails s -p 9000 -b '0.0.0.0'     volumes:        - ".:/slackcron"     ports:       - "9000:9000" networks:   default:     external:       name: <discourse_name> 

after ror application run in same network.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -