我正在尝试在 docker 中运行我的 ng2 应用程序。我有 Docker 文件:
FROM ubuntu:latest
RUN apt-get update
#Install curl & git
RUN apt-get -qq -y install curl
RUN apt-get install -yqq git
#Download and install nodejs-6
RUN curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -yqq nodejs
RUN apt-get install -yqq build-essential
RUN npm install -g angular-cli
#Clone the project
RUN git clone https://github.com/moravianlibrary/RecordManager2.git
WORKDIR /RecordManager2
#Checkout webapp_jobs_branch
RUN git checkout webapp_jobs_branch
#Go to the gui directory
WORKDIR /RecordManager2/cz.mzk.recordmanager.webapp.gui/gui
EXPOSE 4200
RUN npm install
CMD ["ng", "serve"]
构建并运行完成,没有错误:
docker build -t rm-gui .
docker run --name gui -dp 4200:4200 rm-gui
运行应用程序后,我可以看到应用程序确实在运行:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
caa4f1f820d6 rm-gui "ng serve" 23 minutes ago Up 23 minutes 0.0.0.0:4200->4200/tcp gui
但是当我打开页面时http://localhost:4200/
我看到一个错误This site can’t be reached
。我究竟做错了什么?
in your package.json
文件设置如下start
命令
"scripts": {
"ng": "ng",
"start": "ng serve -H 0.0.0.0",
.....
},
in your Dockerfile
将最后一行替换为
CMD ["npm", "start"]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)