尽管前端正确编译,但使用docker-compose up
和ng 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
答案 0 :(得分:0)
更改命令
ng serve
到
ng serve --port 4200 --host 0.0.0.0 --disable-host-check
package.json中的