Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using mongodb - get the ip of the container? #14

Open
goldylucks opened this issue Apr 5, 2016 · 10 comments
Open

using mongodb - get the ip of the container? #14

goldylucks opened this issue Apr 5, 2016 · 10 comments

Comments

@goldylucks
Copy link

in my config file I've set the mongodb url to
mongodb://localhost/nodeparking_dev

but I'm getting this error:
Error: connect ECONNREFUSED 127.0.0.1:27017

is there a way for the node code to know what's the ip of the container?

do u have any examples using dockunit with a db?

@tlovett1
Copy link
Owner

tlovett1 commented Apr 5, 2016

Can you post the config file?

@goldylucks
Copy link
Author

I've tried different types of node images
all make the same error

// server.js
var mongoose = require('mongoose');
var express = require('express');
var app = express();

var config = require('./config/config');

require('mongoose').connect(config.db.url);

// dev/tests
if (config.seed)
  require('./util/seed');

module.exports = app;
// config.js
  db: {
    url: "mongodb://localhost/nodeparking_test"
  }
// Dockunit.json
{
    "containers": [

        {
            "prettyName": "Node Latest",
            "image": "google/nodejs:latest",
            "beforeScripts": [
                "npm install",
                "npm install -g mocha"
            ],
            "testCommand": "mocha server/**/*.spec.js -w"
        }

    ]
}

@tlovett1
Copy link
Owner

tlovett1 commented Apr 5, 2016

Hey Adam, the google/nodejs image does not have Mongo in it. Here are your options:

  1. Use a different image that has Node.js and Mongo.
  2. Install Mongo as a part of beforeScripts (not recommended).
  3. Create your own image using google/nodejs as a parent that installs Mongo.

@tlovett1
Copy link
Owner

tlovett1 commented Apr 5, 2016

Did you try the Dockunit.json wizard on Dockunit.io? It uses the dockunit/prebuilt-images:nodejs-mongodb-mocha-jasmine-4.2.1 image.

@goldylucks
Copy link
Author

Which wizard?

I changed the image to dockunit/prebuilt-images:nodejs-mongodb-mocha-jasmine-4.2.1
but I still get the same error

which makes sense, since my app doesn't know the ip of the docker container, so I can't set it in my config file.

I have no way to hook the db to docker

Does this makes since?

does dockunit exposes any ENV_VARIABLES like it's ip?

so maybe I could go
url: "mongodb://${process.env.DOCKUNIT_IP}/nodeparking_test"

@tlovett1
Copy link
Owner

tlovett1 commented Apr 8, 2016

Hmm I see. Can't you just check if Dockunit is running and check Mongodb on localhost?

@goldylucks
Copy link
Author

what do u mean check mongoDB on localost?

it is already pointing to localhost
mongodb://localhost/nodeparking_dev

@tlovett1
Copy link
Owner

tlovett1 commented Apr 8, 2016

So can't you just reference the Mongo instance like that? Why do you need the container IP?

@goldylucks
Copy link
Author

because I get the reference error I posted
Error: connect ECONNREFUSED 127.0.0.1:27017

@tlovett1
Copy link
Owner

Hmm, I would debug by starting the Docker container manually and seeing what is going on with Mongo inside of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants