dokku / dokku-mongo

a mongo plugin for dokku
MIT License
174 stars 32 forks source link

Can't connect to exposed service #203

Closed chgad closed 5 months ago

chgad commented 5 months ago

Description of problem

I'm trying to setup an Instance of Mongo-express via docker-compose to manage a MongoDB created by dokku-mongo.

I have the following docker-compose.yml file, basically just defining the Envvariables:

version: "3" 
services: 
  db-interface: 
    image: mongo-express 
    restart: "no" 
    ports: 
      - "5081:8081" 
    domainname: MY.DOMAIN.com 
    environment: 
      ME_CONFIG_MONGODB_ADMINUSERNAME: time_vault_staging_db
      ME_CONFIG_MONGODB_ADMINPASSWORD: some-created-passwd
      ME_CONFIG_MONGODB_URL: mongodb://my_mongo_staging_db:some-created-passwd@127.0.0.1:27017/ 

The dokku mongo:info of the my_mongo_staging_db is as follows:

=====> my_mongo_staging_db mongo service information
       Config dir:          /var/lib/dokku/services/mongo/my_mongo_staging_db/config
       Config options:       --storageEngine wiredTiger --auth 
       Data dir:            /var/lib/dokku/services/mongo/my_mongo_staging_db/data
       Dsn:                 mongodb://my_mongo_staging_db:some-created-passwd@dokku-mongo-my-mongo-staging-db:27017/my_mongo_staging_db
       Exposed ports:       27017->127.0.0.1:27017 27018->27018 27019->27019 28017->28017 
       Id:                  49557db0569e694654b1d6765b5ba099f775e6296db0d18d6de5820189874b11
       Internal ip:         172.20.0.7               
       Initial network:                              
       Links:               time-vault-staging       
       Post create network:                          
       Post start network:                           
       Service root:        /var/lib/dokku/services/mongo/time_vault_staging_db
       Status:              running                  
       Version:             mongo:7.0.2  

As you can see i already exposed the dokku-mongo service to 127.0.0.1:27017.

However, when i try to start the Mongo Express app via docker-compose up I encouter:

db-interface_1  | /docker-entrypoint.sh: line 15: /dev/tcp/127.0.0.1/27017: Connection refused
db-interface_1  | Thu Apr  4 10:50:04 UTC 2024 retrying to connect to 127.0.0.1:27017 (2/10)
db-interface_1  | /docker-entrypoint.sh: connect: Connection refused

Did I do the Expose incorrectly or mix up the database credentials?

How reproducible

Use docker-compose.yml above. Create dokku-mongo service as usual. Expose Port 127.0.0.1:27017. Start App

Steps to Reproduce

1. 2. 3.

Actual Results

Mongo-Express App does not connect to dokku-mongo db.

Expected Results

Connection successfull and startup of Mongo-Express app.

Environment Information

dokku report APP_NAME output

It's a dokku-mongo service. Issueing this command yields in a ! App time_vault_staging_db does not exist message.

josegonzalez commented 5 months ago

This has to do with docker networking. 127.0.0.1 in a container points at that container, not at the host. You'll need to either connect them both to the same network, route to the public server ip, or somehow reference the docker internal host name as shown here: https://stackoverflow.com/a/70725882