0

I am trying to run two docker containers on a VPS machine that has Ubuntu 15.10 and am using docker-compose for this. One container is a mongodb server and the other runs my web app written in node.js/sails.js.

I wrote the following in docker-compose.yml so that docker-compose up will run both containers. I am mounting the web app to the directory /host in the web app docker container and would like to do a port mapping 3050:1337 (host:docker). In order to run the web app, I used the command label and use bash to change directory and execute sails lift command, however, it does not work. I guess my following script is wrong:

MongoDB:
  image: mongo

MyAPI:
  image: sailsjs-microservice:dev
  volumes:
   - /root/Code/node/My-API:/host
  command: bash -c "cd /host && sails lift"
  ports:
   - "3050:1337"

I appreciate your help

1
  • Hmm I guessing you forgot to add a link to your db in your API section. The API service should be able to connect to that mongo instance right? Commented Jun 20, 2016 at 20:18

2 Answers 2

1

I haven't seen the logs in your sailsjs-microservice container but I think you should add a link to your mongo container in your API container.

One way to do it's adding this to your compose file:

MyApi:
   links:
    - mongo:mongo

The first mongo is the name of the image you want to link, the second is an alias, could be db for example. Docker will export the container's IP address as a environment variables and also add a /etc/hosts entry for that so that you could reference it in your service`s code by connecting to mongo:27017 (where mongo is the alias defined in the compose file and 27017 is the default port).

Take a look on link environment variables

Sign up to request clarification or add additional context in comments.

Comments

1
MongoDB:
  image: mongo
  networks:
      - myApi-tier

MyAPI:
  image: sailsjs-microservice:dev
  volumes:
   - /root/Code/node/My-API:/host
  command: bash -c "cd /host && sails lift"
  networks:
      - myApi-tier

networks:
  myApi-tier:

You can try with the network, now inside your service to resolve mongodb you can use the standard port and like uri MongoDB.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.