Access to MongoDB service from docker container

I’m trying to setup mongo db service on Travis to be used for my integration tests running in the docker container. My travis configuration that initializes mongodb is:

    - MONGODB_URI: mongodb://fillrx_test:test@
  - docker
  - mongodb

  - sleep 15
  - mongo fillrx_test_db --eval 'db.createUser({user:"fillrx_test", pwd:"test",roles:["readWrite"]});'
  - docker build -t jeremycod/api-test -f ./server/ ./server

  - docker run --env MONGODB_URI -e CI=true jeremycod/api-test npm test

  - docker build -t jeremycod/fillrx-client ./client
  - docker build -t jeremycod/fillrx-nginx ./nginx
  - docker build -t jeremycod/fillrx-api ./server
  # Log in to the docker CLI
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin

  # Take those images and push them to docker hub
  - docker push jeremycod/fillrx-client
  - docker push jeremycod/fillrx-nginx
  - docker push jeremycod/fillrx-api

  provider: elasticbeanstalk
  region: 'ca-central-1'
  app: 'Fillrx'
  env: 'Fillrx-env'
  bucket_name: 'mys3bucketname'
  bucket_path: 'assets'
    branch: master
  access_key_id: $AWS_ACCESS_KEY
  secret_access_key: $AWS_SECRET_KEY

However, this fails on Travis with the connection refused error:

1) Create address endpoint /api/v1/address/user/userId

       "before all" hook: connectToTestDB for "Create address with correct input":

       MongoNetworkError: failed to connect to server [] on first connect [Error: connect ECONNREFUSED

       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)  {

            name: 'MongoNetworkError'


Obviously, MongoDB service is not available from the docker container on this address, but I can’t find anywhere in documentation how to correctly setup this.

Anyone can help with this?


For starters, I don’t see you starting the MongoDB service anywhere.

Can’t say anything else for sure without seeing the entire build.

Googling “access host from docker container” finds (though it’s rather old and probably outdated) and

Thanks. Solution suggested in this article works.

   - docker run --network host -e CI=true mydocker/api-test npm test