0

I have a docker container that has Rails and mongoDB running in it. I set the mongo configuration to use a unix socket for the connection because the only resource that really needs to connect to it (the rails app) is running in the container.
Whenever I try to connect to the mongo shell I get this error:

[main] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017'

I have my mongoDB configuration set up like this:

#mongod.conf - 3.4
    storage:
        dbPath: "/var/lib/mongodb"
        directoryPerDB: true
        journal:
            enabled: true
    systemLog:
        destination: file
        path: "/var/log/mongodb/mongodb.log"
        logAppend: true
        timeStampFormat: iso8601-utc
    processManagement:
        fork: true
    net:
        bindIp: 127.0.0.1
        port: 27017
        wireObjectCheck: false
        unixDomainSocket:
            enabled: true
    net:
      ssl:
        mode: requireSSL
        PEMKeyFile: /etc/ssl/certs/db/mongodb.pem


    security:
      authorization: enabled

Has anyone else run into this issue as well? Is there a best practice on mongoDB configuration within docker containers?

1 Answer 1

2

You might need to give which docker image you are using to start with, and if it isn't a mongo centric container, how is mongo being installed and started?

If you are not using the official image here: https://hub.docker.com/_/mongo/ you might try adding your application to it for debugging purposes

e.g.

FROM mongo

# System ruby
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl ruby \
&& rm -rf /var/lib/apt/lists/*

RUN bash -l -c 'ruby -v'

# Or Get a new version of ruby
ENV GET_RUBY ruby-2.3.3

RUN curl -sSL https://get.rvm.io | bash -s stable
RUN bash -c 'source /etc/profile.d/rvm.sh && rvm install $GET_RUBY && rvm use --default $GET_RUBY'
RUN bash -l -c 'ruby -v'
add . /assets

Also, as a best practice you should not have the mongo service inside your application container. Instead, fire up the official one and utilize it from your other container, here is a docker-compose.yml from a project I use that has mongo in it:

version: '2'
services:
  db:
    image: mongo
    ports:
      - "27017:27017"
  web:
    build: .
    command: npm start
    volumes:
      - .:/meanshop
    ports:
      - "7000:7000"
    depends_on:
      - db
    environment:
      PORT: 7000
      MONGODB_DB_URL: "mongodb://db/meanshop"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.