我有一个工作角度5应用程序,我正在努力使与对接-撰写工作。
虽然许多人都遇到过类似的问题,但建议的解决办法对我来说并不管用:
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
这是我的船坞-Compose.yml
version: '3'
services:
webui-ng:
container_name: bcrm-webui-ng
build: ./webui-angular
ports:
- 4200:4200 下面是Docker文件,它位于./webui-角下面。
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时,总是会收到火狐中的“连接被重置”错误。
这是命令行的输出
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.发布于 2018-09-25 09:30:54
进一步研究后,我知道问题不是在码头端,而是跟随命令不起作用。
npm run ng serve --host 0.0.0.0 --disable-host-check 但只有通过才行。
ng serve --host 0.0.0.0 --disable-host-check 发布于 2018-09-24 14:28:07
你的码头不是第一次收到的port地址。这种情况发生在每次run而不是码头start时。它只是将4200端口与第一个容器绑定在一起(如果运行docker ps -a,您将看到它)。
解决办法是
--name来完成。你可以选择其中之一。
https://stackoverflow.com/questions/52481177
复制相似问题