Software in docker not responding to exposed ports

Hello all.
I must be doing something wrong, I hope I can get some help here.

I’m trying to migrate from vagrant to docker, and for a legacy project I need a set-up with Apache/PHP/MySQL and MongoDB
I have the DAMP stack working, but the mongo and mongo-express web-client have me boggled.

What I am trying to do:

access mongo on exposed port 27017 using Robo 3T
access mongo-express as alternative to Robo on exposed port 8081

How am I trying to do that:

snippet from docker-compose.yml

  mongo:
    container_name: mongodb
    image: mongo
    restart: always
    volumes:
      - ./.data/mongo:/data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: fake
      MONGO_INITDB_ROOT_PASSWORD: fake
    ports:
      - 27017:27017
  mongoExpress:
    image: mongo-express
    container_name: me
    depends_on: 
      - mongo
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: fake
      ME_CONFIG_MONGODB_ADMINPASSWORD: fake

then open Robo 3T and connect to localhost:27017 or 127.0.0.1:27017, error response:

Cannot connect to the MongoDB at 127.0.0.1:27017.
Error:
Network error while attempting to run command 'saslStart' on host '127.0.0.1:27017'

open localhost:8081 in browser, or 127.0.0.1:8081, no response
$ curl -I http://localhost:8081 returns: “empty response from server”

docker container ls reports the containers running and ports exposed.

CONTAINER ID   IMAGE            <snip>   PORTS                      NAMES
384b91afabe4   docker_web       <snip>   0.0.0.0:8000->80/tcp       php74
952ad36a4e13   mongo-express    <snip>   0.0.0.0:8081->8081/tcp     me
8d09f0ba3a45   mongo            <snip>   0.0.0.0:27017->27017/tcp   mongodb
6274b910d561   mariadb:latest   <snip>   0.0.0.0:13306->3306/tcp    mariadb

the php74 (web) container is working perfectly, why shouldn’t the mongo and me containers? Also, the mariadb container is working perfectly both from the php74 container and with SequelPro on its exposed port.

I noticed the exposed verses internal port difference (the working ones have different host and client ports and the not working ones have identical ports) so I did already try with alternate ports (27018 for mongo and 8181 for mongoExpress) which did not help.

the mongo data store is getting filled, so I know the software is running, or at least ran once and when I enter the container with docker exec -it mongodb /bin/bash and ps -A | grep mongo I see the process running.

As you might suspect, I’m a total noob with Docker but I’m trying to learn. Hopefully anyone can point me to my mistake.

I’m running Docker on a Mac, macOS 10.15, Docker Desktop version 3.4.0, cli version 20.10.7.

Thank you very much in advance!

Remon.

1 Like

Even an empty response is a response, so I’d guess that publishing the ports works? (Despite the depends_on there is no guarantee that MongoDB is actually fully running.)

Like you already tested: that should not matter.

1 Like

Haven’t thought of it that way. And with that, I got the impulse to recheck other stuff I – in fact – took for granted and I have been able to get a little further;

The example given at docker hub for mongo doesn’t work, at least, not out of the box, not without modifications to the php container.
This is regarding authentication.

The “SCRAM-SHA-1” authentication mechanism requires libmongoc built with --enable-ssl

Would love to learn how to fix this, but this is out of scope and not required for a development environment, so for now I disabled authentication by removing the environment-variable definitions for it and now I have a running mongoDB (accessible from php) and mongo express runs also and can connect to mongo, so internally everything is o.k.

I can access MongoExpress from “host” so that exposed port works, but I still cannot access the mongo database using Robo 3T.

The error now is different though;

Cannot connect to the MongoDB at localhost:27017.
Error:
Failed to execute "listdatabases" command.

Yes, I know, Robo 3T is an older, buggy piece of software, but it works for other servers, even over SSH, so I’m not about to swap it out. Will learn how to use MongoExpress for this Docker based project instead.
Maybe I’ll find a way to fix Robo, if so, will post here.

So, wrapping up; I have a working example I can now back-port to the project for which I need to replace vagrant.
Thank you very much for nudging me in the right direction :slight_smile:
If only to remind ourselves of the message on the wall (literally, here, at the office);

Assumption is the mother of all f***-ups
1 Like

I’m quite sure you understand now, but just in case you think one cannot tell the difference:

Your curl -I http://localhost:8081 would throw some connection refused if the port would really not be accessible (like due to a wrong ports mapping, or due to simply nothing listening in the container).

And the “solution” to the Robo 3T problem;

Update to Robo 3T 1.3.x (from 1.2.x) for mongo 4.x support.

Sigh …

Thank you again, Arjan, for guiding me to my own stupid mistakes :wink:

1 Like