angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.13k stars 1.24k forks source link

Developing with Docker-compose -- 'client'-side won't work #2725

Closed koraysels closed 6 years ago

koraysels commented 6 years ago
Item Version
generator-angular-fullstack 5.0.0-rc.2
Node 8
npm 5.6.0
Operating System docker
etc etc
Item Answer
Transpiler TypeScript
Markup HTML
CSS SCSS
Router @angular/router
DB MongoDB
Auth Y
etc etc

I am trying to get this project to run in a docker environment. This is my Dockerfile:

FROM node:8-alpine

RUN apk add --update libc6-compat bash
RUN npm  install -g node-gyp

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json .
RUN npm install

COPY . .

CMD 'npm run start | npm run start:client'

This is my docker-compose.yml file

version: "2"

services:
  web:
    build: .
    command: bash -c "npm run start | npm run start:client"
    ports:
      - "9000:9000"
      - "8080:8080"
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    links:
      - mongo
    environment:
      NODE_ENV: development
      NODE_PATH: /usr/local/lib/node_modules/:/usr/local/lib

  mongo:
    image: mongo:latest
    ports:
      - "27017:27017"
    restart: always
    volumes:
      - 'data:/data/db'

I have succeeded to get the server part up and running and I can access the localhost:9000 and it gives me the 'Loading...' screen. Also I think the client part works, because i have this output:

web_1    | Project is running at http://localhost:8080/
web_1    | webpack output is served from /
web_1    | Content not from webpack is served from ./client/
web_1    | 404s will fallback to app.html

but I cannot browse to the app. http://localhost:8080 gives me a ERR_CONNECTION_REFUSED

any advise ?

koraysels commented 6 years ago

I FOUND IT!

for everyone who's having the same problem :

you need to make sure the dev server and everything you serve from within a docker container is doing this on 0.0.0.0 and not localhost

Awk34 commented 6 years ago

Thanks for sharing your solution. I'm curious, what's your reasoning for wanting to develop the app within a Docker container?