Not able to connect mongodb with Rails container using Docker compose

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 “

  • Do you have any resource explaining how to use Firebase Test lab with GitLab pipeline?
  • Import broker definitions into Dockerized RabbitMQ
  • Prevent docker-machine from downloading newer boot2docker iso?
  • Docker - orchardup/mysql container does not start on Ubuntu 14.04
  • thrift + hbase exception (in docker containers)
  • Run Docker container behind proxy?
  • 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
    

  • Running docker chrome node in EC2 Does Not Download Files
  • Add windows folder in Dockerfile
  • How to use custom name in docker overlay network for containers network name?
  • Install docker on a compute cluster with a shared file-system
  • Add config.txt to docker container
  • Why does `apt install postgresql` not work in a docker container?
  • One Solution collect form web for “Not able to connect mongodb with Rails container using Docker compose”

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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.