1

Getting this error when inserting values in Model through rails console .

"Mongo::Error::NoServerAvailable: No server is available matching preference: # using server_selection_timeout=30 and local_threshold= 0.015 "

Both containers are running fine, but Rails not able to connect mongodb . I have only one Dockerfile.

My docker-compose.yml file contents are:

 version: '2'

services:
  mongo:
    image: mongo:3.0
    command: mongod --smallfiles --quiet
    environment:
      - RAILS_ENV=production
      - RACK_ENV=production
    ports:
      - "27017:27017"

  app:
    depends_on:
      - 'mongo'
      # - 'redis'
    build: .
    ports:
      - '3000:3000'
    volumes:
      - '.:/app'
    command: rails s -b '0.0.0.0'
    env_file:
      - '.env'

volumes:
  mongo:

My Dockerfile :

FROM ruby:2.3.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

ENV APP_HOME /app

RUN mkdir $APP_HOME  
WORKDIR $APP_HOME


ADD Gemfile* $APP_HOME/ 
RUN bundle install


ADD . $APP_HOME
  • What host is your rails application trying to connect to? – Roman Oct 23 '16 at 17:34
  • localhost:27017 – Chirag Batra Oct 24 '16 at 07:16
  • Possible duplicate of [Using Docker I get the error: "SQLSTATE\[HY000\] \[2002\] No such file or directory"](http://stackoverflow.com/questions/40075065/using-docker-i-get-the-error-sqlstatehy000-2002-no-such-file-or-directory) – Roman Oct 24 '16 at 12:34

1 Answers1

0

Did you use mongo(same as the container name mentioned in docker-compose.yml) as your host in mongoid.yml?

gak4u
  • 80
  • 1
  • 6