我正在尝试在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 /我看到一个错误这个网站无法访问.我究竟做错了什么?
最佳答案 在package.json文件中设置以下启动命令
"scripts": {
"ng": "ng",
"start": "ng serve -H 0.0.0.0",
.....
},
在你的Dockerfile中替换最后一行
CMD ["npm", "start"]