With the below setup, I am able to see my website but I am getting an ERR_EMPTY_RESPONSE when I try to register.
When I register I am making a HTTP request to the API.js
which creates/updates the Schema in user.js.
This normally works when not using Docker/Nginx.
I tried connecting to the container Image "mongo" directly, I tried 0.0.0.0:27017
, but I have the feeling my app.js doesn't initially connect to the Mongodb.
Even though the routing to /main /profile etc. works. So I am assuming app.js has been called via index.html
I have a feeling it is a minor thing to make this work, but spent a few hours now and I struggle. I am not using CORS, since I am using Nginx. I am quite new to these concepts, but I think Nginx as a reverse proxy doesn't use CORS?
In docker-compose.yml when I change the directory of the Volume to something that doesn't exist, nothing changes I still get to see my website, as if it doesn't do anything, however when I delete the sentence it gives me a failure so it is being called. Not entirely sure what the Volume does in this file.
docker ps gives me the below output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f58507ed0205 meanchat_web "nginx -g 'daemon ..." 55 seconds ago Up 54 seconds 0.0.0.0:80->80/tcp meanchat_web_1
cddfd8180f1b meanchat_node "nginx -g 'daemon ..." 2 hours ago Up 55 seconds 80/tcp, 0.0.0.0:3000->3000/tcp meanchat_node_1
79a013dd4e51 mongo "docker-entrypoint..." 2 hours ago Up 55 seconds 0.0.0.0:27017->27017/tcp meanchat_mongo_1
app.js:
var mongo= require('mongodb');
//var cors = require('cors');
var mongoose = require('mongoose');
var connect = require('./models/user')
connect.connect('mongodb://localhost/loginapp');
var db = mongoose.connection;
user.js:
module.exports.connect = function(mongoUri, promiseLib){
var mongoDB = mongoose.connect(mongoUri);
return mongoDB
};
DockerFile:
### STAGE 1: Build ###
# We label our stage as ‘builder’
FROM node:8.1.4-alpine as builder
COPY package.json package-lock.json ./
## Storing node modules on a separate layer will prevent unnecessary
pm installs at each build
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
WORKDIR /ng-app
COPY . .
## Build the angular app in production mode and store the artifacts
in dist folder
RUN $(npm bin)/ng build --prod
### STAGE 2: Setup ###
FROM nginx:1.13.3-alpine
## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
## From ‘builder’ stage copy over the artifacts in dist folder to default
nginx public folder
COPY --from=builder ./dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
docker-compose.yml:
version: '3'
services:
web:
build: ./
ports:
- "80:80"
links:
- node
volumes:
- "./dist :/usr/share/nginx/html"
node:
build: ./
ports:
- "3000:3000"
links:
- mongo
mongo:
image: mongo
ports:
- "27017:27017"
main.ts:

