Reputation: 18875
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
Upvotes: 0
Views: 819
Reputation: 1674
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.
Upvotes: 1
Reputation: 2247
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
Upvotes: 1