Containerizing a Sails.js app with Postgres

Hi all! I’m new here and new to docker in general, and even more new to docker-compose.

I’m attempting to containerize a sails.js app that uses postgres using docker compose and I’m really having a rough time with it. I’ve scoured the internet for solutions to my problem and even posted on Stack Overflow. I’m sure there are docker pros here so if someone can help walk me through how to do this, that would be awesome!

Here is the sails app: https://github.com/ArekSredzki/electron-release-server

my Dockerfile has:

FROM node:4-onbuild

ADD package.json package.json
RUN npm install
ADD . .

EXPOSE 1337

CMD ["npm","start"]

and my docker-compose has:

version: "2"
services:
  db:
    image: postgres
    ports: [ "5432:5432" ]
    environment:
    - POSTGRES_PASSWORD=sails
    - POSTGRES_USER=sails
    - POSTGRES_DB=sailspg
  web:
    build: .
    command: "npm start"
    ports: [ "1337:1337" ]
    volumes:
      - .:/usr/src/app
    depends_on: [ db ]
    links:
      - db

in my app.js that actually launches the sails app, I’m attempting to run:

var pg = require("pg");
var conString = "pg://sails:sails@db:5432/sailspg";
var client = new pg.Client(conString);
client.connect();
client.query('CREATE ROLE electron_release_server_user ENCRYPTED PASSWORD \'password\' LOGIN;');
client.query('CREATE DATABASE IF NOT EXISTS electron_release_server OWNER "electron_release_server_user";');
client.query('CREATE DATABASE IF NOT EXISTS electron_release_server_sessions OWNER "electron_release_server_user";');
client.end();

but it can’t seem to connect correctly.

Does anyone have any tips? Am I doing this completely wrong? I wanted this app to be pretty much press a button and it just works.