尽pipe前端使用docker-up up和ng serve正确地编译,只有ng服务才能正常工作

尽pipe前端使用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 

改变你的命令

 ng serve 

 ng serve --port 4200 --host 0.0.0.0 --disable-host-check 

在package.json中