在 Docker 中运行 Angular2 应用程序 [英] Running Angular2 application in Docker
本文介绍了在 Docker 中运行 Angular2 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 docker 中运行我的 ng2 应用程序.我有 Docker 文件:
I'm trying to run my ng2 app in docker. I have the Docker file:
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"]
构建和运行完成没有错误:
building and running finish without errors:
docker build -t rm-gui .
docker run --name gui -dp 4200:4200 rm-gui
运行应用程序后,我可以看到该应用程序确实在运行:
After running the app I can see that app is really running:
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/
时,我看到一个错误 无法访问此站点
.我做错了什么?
but when I open the page http://localhost:4200/
I see an error This site can’t be reached
. What am I doing wrong?
推荐答案
在您的 package.json
文件中设置以下 start
命令
in your package.json
file set the following start
command
"scripts": {
"ng": "ng",
"start": "ng serve -H 0.0.0.0",
.....
},
在您的 Dockerfile
中将最后一行替换为
in your Dockerfile
replace the last line with
CMD ["npm", "start"]
这篇关于在 Docker 中运行 Angular2 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文