I'm trying to access to my mongo database on docker with adminmongo.
Here's my docker-compose.yml
version: '3'
services:
  mongo:
    image: mongo
    volumes:
      - ~/data:/data/db
    restart: always
    expose:
      - 6016
  adminmongo:
    image: mrvautin/adminmongo
    expose:
      - 1234
    links:
      - mongo:mongo
When i do a docker-compose up everything works fine, adminmongo also return me this : adminmongo_1_544d9a6f954c | adminMongo listening on host: http://localhost:1234
But when i go to localhost:1234 my navigator is telling me this page doesn't exist.
Here's what a docker ps return me :
$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                 NAMES
9c27d4a89254        mrvautin/adminmongo   "/bin/sh -c 'node ap…"   38 seconds ago      Up 33 seconds       1234/tcp              iris_adminmongo_1_544d9a6f954c
2a7496a8c56a        mongo                 "docker-entrypoint.s…"   40 minutes ago      Up 38 seconds       6016/tcp, 27017/tcp   iris_mongo_1_7f00356a3adc
                I've found 2 issues here:
1st: Exposing a port is not enough. expose is just documentation, you need to publish (bind) a port to the host to be reachable. This is how it's done:
ports:
  - 1234:1234
2nd: you have to configure adminmongo to listen to 0.0.0.0 because by default it starts listening on 127.0.0.1 and this makes it accessible only inside the container itself. From the documentation page you've included in your question, the Configuration section states that this can be done by passing an environment variable:
All above parameters are usable through the environment which makes it very handy to when using adminMongo as a docker container! just run
docker run -e HOST=yourchoice -e PORT=1234 ...
Since you are using docker-compose, this is done by the following:
environment:
  - HOST=0.0.0.0
Working example:
version: '3'
services:
  mongo:
    image: mongo
    volumes:
      - ~/data:/data/db
    restart: always
    expose:
      - 6016
  adminmongo:
    image: mrvautin/adminmongo
    ports:
      - 1234:1234
    environment:
      - HOST=0.0.0.0
                        Example of docker-compose works :
version: '3'
services:
  server:
    container_name: docker_api_web_container
    image: docker_api_web
    build: .
    volumes:
      - ./src:/usr/src/node-app/src
      - ./package.json:/usr/src/node-app/package.json
    environment:
     - ENV=DEVELOPMENT
     - PORT=4010
    ports:
      - '9000:4010'
    depends_on:
      - 'mongo'
  mongo:
    container_name: docker_mongo_container
    image: 'mongo'
    ports:
      - '27017:27017'
  adminmongo:
    container_name: docker_adminmongo_container
    image: mrvautin/adminmongo
    links: ['mongo:mongo']
    environment:
      - HOST=0.0.0.0
    ports:
      - '1234:1234'
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With