I'm still not able to properly run docker-compose in my OVH VPS.
I'm developing a small nodeJS application using mongodb. My configuration works on my PC (Windows 7), but when I push it on my VPS the result is not as expected.
My docker-compose.yml
db:
image: mongo
ports:
- "27017:27017"
command: "--smallfiles --logpath=/dev/null"
web:
build: .
volumes:
- .:/app
ports:
- "3000:3000"
links:
- db
environment:
PORT: 3000
My Dockerfile (for the nodeJS part)
FROM node:onbuild
WORKDIR /app
ADD package.json /app/package.json
RUN npm install && npm ls
RUN mv /app/node_modules /node_modules
EXPOSE 3000
CMD [ "node", "server.js" ]
My nodeJS server
var mongoose = require('mongoose');
var express = require('express');
var MONGO_DB;
var DOCKER_DB = process.env.DB_PORT;
if ( DOCKER_DB ) {
MONGO_DB = DOCKER_DB.replace( 'tcp', 'mongodb' ) + '/app';
} else {
MONGO_DB = process.env.MONGODB;
}
var retry = 0;
mongoose.connect(MONGO_DB);
const app = express();
app.get('/', function (req, res) {
res.send('Hello world\n');
});
app.listen(process.env.PORT || 3000);
The docker version on my server (Ubuntu 14.04)
Client:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Tue Apr 26 23:30:23 2016
OS/Arch: linux/amd64
Server:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Tue Apr 26 23:30:23 2016
OS/Arch: linux/amd64
When I run:
docker-compose up -d --build
All works fine, but at the end only the mongo container is running and the NodeJS is stopped.
Anyone has an idea?
I found a solution ! MyDockerfile looks like this
FROM node:onbuild
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 3000
CMD [ "node", "server.js" ]
And the docker-compose.yml
db:
image: mongo
ports:
- "27017:27017"
web:
build: .
volumes:
- .:/app
ports:
- "3000:3000"
links:
- db
All works fine right now :)