在Docker中运行Angular2应用程序

我试图在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"] 

build设和运行完成没有错误:

 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 。 我究竟做错了什么?

在你的package.json文件中设置下面的start命令

  "scripts": { "ng": "ng", "start": "ng serve -H 0.0.0.0", ..... }, 

在你的Dockerfile最后一行代替

 CMD ["npm", "start"]