Graylog container cannot connect to MongoDB container

Your MongoDB initialization file is incorrect.

The following setup works for me™:

docker-compose.yml:

version: '2'
services:
  # MongoDB: https://hub.docker.com/_/mongo/
  mongodb:
    image: mongo:3
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=drUqGGCMh
    volumes:
      - ./graylog.js:/docker-entrypoint-initdb.d/graylog.js:ro
  # Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/docker.html
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.6.10
    environment:
      - http.host=0.0.0.0
      - discovery.type=single-node
      # Disable X-Pack security: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/security-settings.html#general-security-settings
      - xpack.security.enabled=false
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 1g
  # Graylog: https://hub.docker.com/r/graylog/graylog/
  graylog:
    image: graylog/graylog:2.4.5-1
    environment:
      # CHANGE ME!
      - GRAYLOG_PASSWORD_SECRET=somepasswordpepper
      # Password: admin
      - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
      - GRAYLOG_WEB_ENDPOINT_URI=http://127.0.0.1:9000/api
      - GRAYLOG_MONGODB_URI=mongodb://graylog:vWGzncmBe9@mongodb:27017/graylog
      - GRAYLOG_MESSAGE_JOURNAL_ENABLED=false
    links:
      - mongodb
      - elasticsearch
    ports:
      # Graylog web interface and REST API
      - 9000:9000

MongoDB initialization file (graylog.js):

graylog = db.getSiblingDB('graylog');
graylog.createUser(
  {
    user: "graylog",
    pwd: "vWGzncmBe9",
    roles: [
      { role: "dbOwner", db: "graylog" }
    ]
  }
);

Graylog REST API:

$ curl -H 'Accept: application/json' 'http://localhost:9000/api/?pretty=true'
{
  "cluster_id" : "038bc07e-58d6-4bd8-93a1-15c124aafc78",
  "node_id" : "80851cbe-2787-429d-a817-d320b3ef1bcc",
  "version" : "2.4.5+8e18e6a",
  "tagline" : "Manage your logs in the dark and have lasers going and make it look like you're from space!"
}
$ curl -u admin:admin -H 'Accept: application/json' 'http://localhost:9000/api/system/cluster/stats/mongo?pretty=true'
{
  "servers" : [ "mongodb:27017" ],
  "build_info" : {
    "version" : "3.6.3",
    "git_version" : "9586e557d54ef70f9ca4b43c26892cd55257e1a5",
    "sys_info" : "deprecated",
    "loader_flags" : null,
    "compiler_flags" : null,
    "allocator" : "tcmalloc",
    "version_array" : [ 3, 6, 3, 0 ],
    "javascript_engine" : "mozjs",
    "bits" : 64,
    "debug" : false,
    "max_bson_object_size" : 16777216
  },
  "host_info" : null,
  "server_status" : null,
  "database_stats" : {
    "db" : "graylog",
    "collections" : 26,
    "objects" : 166,
    "avg_obj_size" : 413.8313253012048,
    "data_size" : 68696,
    "storage_size" : 307200,
    "num_extents" : 0,
    "indexes" : 51,
    "index_size" : 528384,
    "file_size" : null,
    "ns_size_mb" : null,
    "extent_free_list" : null,
    "data_file_version" : null
  }
}