虽然前端编译正确,但使用docker-compose和ng服务仅适用于ng服务

时间:2017-09-06 06:44:51

标签: javascript angular typescript docker

尽管前端正确编译,但使用docker-compose upng serve只能正常使用ng serve。当我打开localhost:4200时,我的网站没有加载。 ng serve正常工作后。我想用Docker运行它。在这两种情况下,我得到:

angular_1  | ** NG Live Development Server is running on http://localhost:4200 **
angular_1  | Hash: 23dc61d32587641214e0                                                                
angular_1  | Time: 25229ms
angular_1  | chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 222 kB {4} [initial] [rendered]
angular_1  | chunk    {1} main.bundle.js, main.bundle.js.map (main) 113 kB {3} [initial] [rendered]
angular_1  | chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 38 kB {4} [initial] [rendered]
angular_1  | chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 6.34 MB [initial] [rendered]
angular_1  | chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
angular_1  | webpack: Compiled successfully.

前端目录中的Dockerfile:

# Create image based on the official Node 6 image from dockerhub
FROM node:6

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package.json /usr/src/app

# Install dependecies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app

# Expose the port the app runs in
EXPOSE 4200

# Serve the app
CMD ["npm", "start"]

我在主目录中的docker-compose.yml:

version: '3'

services:
  db:
    image: postgres
  django:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
  angular:
    build: frontend
    ports:
      - "4200:4200"
    depends_on:
      - django

1 个答案:

答案 0 :(得分:0)

更改命令

ng serve

ng serve --port 4200 --host 0.0.0.0 --disable-host-check
package.json中的