Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AdminMongo with docker-compose doesn't work

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

like image 602
Anatole Lucet Avatar asked Dec 24 '22 00:12

Anatole Lucet


2 Answers

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
like image 97
tgogos Avatar answered Dec 28 '22 09:12

tgogos


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'
like image 23
Anis ABID Avatar answered Dec 28 '22 11:12

Anis ABID