0

This is my doocker-compose.yml file

version: '3.1'

services:

  mongo:
    image: mongo
    restart: always
    container_name: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

  mongo-express:
    image: mongo-express
    restart: always
    depends_on:
      - mongo
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example

When i run $ sudo docker-compose up I get the following ...

mongo-express_1  | Waiting for mongo:27017...
mongo-express_1  | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
mongo            | {"t":{"$date":"2020-11-11T19:30:18.053+00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.055+00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.056+00:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.057+00:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"84a58d09b1ca"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.057+00:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","openSSLVersion":"OpenSSL 1.1.1  11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.057+00:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"18.04"}}}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.057+00:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"},"security":{"authorization":"enabled"}}}}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.087+00:00"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/data/db","storageEngine":"wiredTiger"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.087+00:00"},"s":"I",  "c":"STORAGE",  "id":22297,   "ctx":"initandlisten","msg":"Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem","tags":["startupWarnings"]}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.088+00:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=256M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:18.726+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1605123018:726666][1:0x7f5a73e15a80], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 4 through 5"}}
mongo-express_1  | Wed Nov 11 19:30:18 UTC 2020 retrying to connect to mongo:27017 (2/5)
mongo-express_1  | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1  | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
mongo            | {"t":{"$date":"2020-11-11T19:30:18.800+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1605123018:800799][1:0x7f5a73e15a80], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 5 through 5"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.003+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1605123019:3557][1:0x7f5a73e15a80], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Main recovery loop: starting at 4/6528 to 5/256"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.129+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1605123019:129560][1:0x7f5a73e15a80], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 4 through 5"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.220+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1605123019:220139][1:0x7f5a73e15a80], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 5 through 5"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.279+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1605123019:279027][1:0x7f5a73e15a80], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.279+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1605123019:279109][1:0x7f5a73e15a80], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global oldest timestamp: (0, 0)"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.316+00:00"},"s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":1228}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.316+00:00"},"s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.417+00:00"},"s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.607+00:00"},"s":"I",  "c":"STORAGE",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.648+00:00"},"s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.651+00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.651+00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.651+00:00"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
mongo-express_1  | Wed Nov 11 19:30:19 UTC 2020 retrying to connect to mongo:27017 (3/5)
mongo            | {"t":{"$date":"2020-11-11T19:30:19.740+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.28.0.3:46578","connectionId":1,"connectionCount":1}}
mongo            | {"t":{"$date":"2020-11-11T19:30:19.741+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn1","msg":"Connection ended","attr":{"remote":"172.28.0.3:46578","connectionId":1,"connectionCount":0}}
mongo-express_1  | Welcome to mongo-express
mongo-express_1  | ------------------------
mongo-express_1  | 
mongo-express_1  | 
mongo-express_1  | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1  | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1  | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongo            | {"t":{"$date":"2020-11-11T19:30:20.565+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.28.0.3:46580","connectionId":2,"connectionCount":1}}
mongo            | {"t":{"$date":"2020-11-11T19:30:20.586+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn2","msg":"client metadata","attr":{"remote":"172.28.0.3:46580","client":"conn2","doc":{"driver":{"name":"nodejs","version":"2.2.24"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"5.4.0-1028-gcp"},"platform":"Node.js v12.19.0, LE, mongodb-core: 2.1.8"}}}
mongo-express_1  | Database connected
mongo            | {"t":{"$date":"2020-11-11T19:30:20.936+00:00"},"s":"I",  "c":"ACCESS",   "id":20250,   "ctx":"conn2","msg":"Successful authentication","attr":{"mechanism":"SCRAM-SHA-1","principalName":"root","authenticationDatabase":"admin","client":"172.28.0.3:46580"}}
mongo-express_1  | Admin Database connected
mongo            | {"t":{"$date":"2020-11-11T19:30:20.944+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.28.0.3:46582","connectionId":3,"connectionCount":2}}
mongo            | {"t":{"$date":"2020-11-11T19:30:21.028+00:00"},"s":"I",  "c":"ACCESS",   "id":20250,   "ctx":"conn3","msg":"Successful authentication","attr":{"mechanism":"SCRAM-SHA-1","principalName":"root","authenticationDatabase":"admin","client":"172.28.0.3:46582"}}

I have tried to manually create network, expose ports, change names, bing ports to host, change ports etc... The most fanny thing that this example taken from https://hub.docker.com/_/mongo. The only thing I've added was

    depends_on:
      - mongo

I also tried to add environment variable for mongo-express ME_CONFIG_MONGODB_SERVER=mongo but it is default one so did't work ;(

Any suggestions?

1 Answers1

0

You are using version 3.1 of compose. Either update that version to 3.8 and use docker-compose networks like this:

version: '3.8'

services:
  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
    networks:
      - mongo-net
  mongo-express:
    image: mongo-express
    restart: always
    networks:
      - mongo-net
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
networks:
  mongo-net:
    driver: bridge

Or use links with version 3.1 like this:

version: '3.1'

services:

  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
  mongo-express:
    links:
      - "mongo"
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example

In both cases you should see something like this in your mongo-express logs:

mongo-express_1  | Welcome to mongo-express
mongo-express_1  | ------------------------
mongo-express_1  | 
mongo-express_1  | 
mongo-express_1  | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1  | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1  | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongo-express_1  | Database connected
mongo-express_1  | Admin Database connected
mehrdadep
  • 972
  • 1
  • 15
  • 37
  • Thank you for answering! But unfortunately nothing has changed :( In both cases I get the same error – Maksym Antoshkin Nov 12 '20 at 09:07
  • What is your docker-compose version? `docker-compose version` – mehrdadep Nov 12 '20 at 12:42
  • When I run docker-compopse version I get the following `docker-compose version 1.27.4, build 40524192 docker-py version: 4.3.1 CPython version: 3.7.7 OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019` – Maksym Antoshkin Nov 12 '20 at 15:14
  • and what about `docker --version`? – mehrdadep Nov 12 '20 at 16:24
  • Docker version is 19.03.13, build 4484c46d9d – Maksym Antoshkin Nov 12 '20 at 18:04
  • Just tested with your version of docker-compose and docker engine with the first compose file (version 3.8) and it works fine. Use these command and try again. `docker-compose down` - `docker container prune` - `docker network prune` – mehrdadep Nov 12 '20 at 18:51
  • And if by problem you mean the connection refused before mongo service is up and listening I must tell that's not a problem. That is the normal behavior. If you want to avoid mongo-express from even trying, use `wait-for-it` shell commands – mehrdadep Nov 12 '20 at 19:08