Mongo rack connection

I have a rails app with mongodb, in a development environment. Failed to connect mongodb with docker. Can connect to local mongodb with the same mongoid configuration. I tried changing host as localhost to 0.0.0.0 but didn't work. What's missing in the settings?

My doubt is that mongo in Docker didn't start or was not tied. If I make changes to the mongoid config to read :: closest, it says no nodes found.

error message, Moped :: Errors :: ConnectionFailure in product index #

Failed to connect to primary node for replica set #]>

Dockerfile

#FROM ruby:2.2.1-slim
FROM rails:4.2.1
MAINTAINER Sandesh Soni, <my@email.com>
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN mkdir /gmv
WORKDIR /gmv
# Add db directory to /db
ADD Gemfile /gmv/Gemfile
RUN bundle install
ADD ./database /data/db
ADD . /gmv

      

Docker-compose.yml

web:
  build: .
  command: bundle exec rails s -p 3000 -b '0.0.0.0'
  volumes:
    - .:/gmv
  ports:
    - "3000:3000"
  links:
    - db
db:
  image: mongo
  command: "--smallfiles --bind_ip 0.0.0.0 --port 27027 -v"
  volumes:
    - data/mongodb:/data/db
  ports:
    - "27017:27017"

      

+3


source to share


1 answer


On the host machine, execute docker run yourapp env

, then in the browser, find the IP address associated with your database. This IP address and port must be used to connect to the database running in the container.



A similar question has been asked here

0


source







All Articles