2

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
chrisonstack
  • 175
  • 2
  • 11

2 Answers2

1

is your server.js file on the same directory as the Dockerfile? I think the problem is that server.js has to also be in WORKDIR. And also I think you're copying your code to the container on this one, use CP instead of RUN mv. Try this:

FROM node:onbuild

WORKDIR /app

ADD package.json /app/package.json
RUN npm install && npm ls
COPY /app/node_modules /node_modules

ADD server.js /app/server.js # add this line

EXPOSE 3000

CMD [ "node", "server.js" ]

updated it: I incorrectly wrote CP instead of the correct COPY, Sorry :(

paolord
  • 389
  • 1
  • 7
  • I tried your solution, but the result is still the same. The "CP" command was not found, so I kept the older line. – chrisonstack May 05 '16 at 18:29
  • sorry, its supposed to be COPY not CP, I updated my answer, my bad – paolord May 05 '16 at 18:33
  • I tried with COPY and it fails too. Basically docker-compose is not installed on OVH's VPS. Even if it's possible to install it, maybe we can't use it... furthermore I found some tutorials provided by OVH and it explains How to set up three containers without docker-compose. – chrisonstack May 06 '16 at 17:04
  • oh, I thought you ran docker-compose on ovh, – paolord May 07 '16 at 06:17
0

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 :)

chrisonstack
  • 175
  • 2
  • 11