【发布时间】:2019-02-28 01:46:51
【问题描述】:
我有一个工作的 Angular 5 应用程序,我正在努力使用 docker-compose。
虽然很多人都遇到过类似的问题,但建议的解决方案对我不起作用:
Access Angular app running inside Docker container
Cannot access nodejs app on browser at localhost:4200 (docker run -p 4200:4200 ....)
nodejs app doesn't connect to localhost when running within a docker container
ng serve not working in Docker container
not able to access angular2 app from docker container
这是我的 docker-compose.yml
version: '3'
services:
webui-ng:
container_name: bcrm-webui-ng
build: ./webui-angular
ports:
- 4200:4200
以下是位于 ./webui-angular 下的 Docker 文件。
FROM node:9.6.1
# Create app directory
WORKDIR /usr/src/app
COPY package*.json ./
# Install app dependencies
RUN npm install
# Bundle app source
COPY . .
# Expose API port to the outside
EXPOSE 4200
# Launch application
#CMD ["npm","run ng serve"]
#CMD ["npm", "run", "ng", "serve", "--host", "0.0.0.0"]
#CMD ["npm", "run", "ng", "serve", "--host", "0.0.0.0", "--port", "4200"]
#ENTRYPOINT ["npm", "run", "ng", "serve", "--open", "--host", "0.0.0.0", "--port", "4200"]
CMD npm run ng serve --host 0.0.0.0
请注意,最后几行注释的所有命令都不起作用。也就是说,当我打开 http://localhost:4200 时,我总是在 Firefox 中收到“连接已重置”错误
这是命令行输出
bcrm-webui-ng |
bcrm-webui-ng | > Xyz@0.1.0 ng /usr/src/app
bcrm-webui-ng | > ng "serve" "0.0.0.0"
bcrm-webui-ng |
bcrm-webui-ng | ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
bcrm-webui-ng | Date: 2018-09-24T14:03:38.509Z
bcrm-webui-ng | Hash: 4ac012def02ed7e0a08a
bcrm-webui-ng | Time: 19848ms
bcrm-webui-ng | chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
bcrm-webui-ng | chunk {main} main.bundle.js, main.bundle.js.map (main) 1.81 MB {vendor} [initial] [rendered]
bcrm-webui-ng | chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 221 kB {inline} [initial] [rendered]
bcrm-webui-ng | chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 28.2 kB {inline} [initial] [rendered]
bcrm-webui-ng | chunk {vendor} vendor.bundle.js, vendor.bundle.js.map (vendor) 4.25 MB [initial] [rendered]
bcrm-webui-ng |
bcrm-webui-ng | webpack: Compiled successfully.
【问题讨论】:
-
您第一次成功执行 docker compose 时遇到过这个问题吗?还是后续问题?
-
这是后续问题。我尝试了很多次。