在Docker中运行Angular2应用程序

时间:2016-11-25 07:59:18

标签: angular docker angular-cli

我正在尝试在docker中运行我的ng2应用程序。我有Docker文件:

        System.Windows.Controls.RichTextBox rTb = new System.Windows.Controls.RichTextBox();
        yourElementHost.Child = rTb;

构建并运行完成且没有错误:

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

1 个答案:

答案 0 :(得分:1)

package.json文件中设置以下start命令

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

Dockerfile中用

替换最后一行
CMD ["npm", "start"]