Docker中的AngularJS和NodeJS应用 [英] AngularJS and NodeJS app in Docker
问题描述
我有一个angular和nodejs应用程序。
API的(nodejs)在端口8888上运行。
Angular在端口8080上运行
I have an angular and nodejs app. The API's (nodejs) is running on port 8888 The Angular is running on port 8080
现在,应用程序在docker容器中运行。
容器运行者:
Now the app is running in a docker container. The container is running by:
docker run -d -p 49160:8080 --name app localhost:5000/test/app
问题是。现在,我可以在localhost:49160上访问API,但是我不知道如何访问我的角度。哪个端口在另一个端口上运行
The problem is. Now I'm able to visiting the API's on localhost:49160 but I don't know how to access my angular. Which is running on another port
我需要2个容器吗?在每个教程中,我都在同一容器中看到它。
Do I need 2 containers? In each tutorial I see it in the same container.
编辑:这是我的dockerfile:
this is my dockerfile:
FROM node
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN npm install -g bower
RUN npm install -g gulp
# Install app dependencies
COPY . /usr/src/app/
RUN bower install
RUN npm install
RUN gulp build
EXPOSE 8080
CMD [ "node", "server.js" ]
我的运行命令是:
docker run -d -p 49160:8080 -p 8888:8888 --name app localhost:5000/test/app
我的角度在端口8080和8888的nodejs上运行。
My angular is running on port 8080 and nodejs on 8888.
推荐答案
您可以通过重复 -p
标志来暴露Docker容器的多个端口:
You can expose multiple ports of your Docker container by repeating the -p
flag:
docker run -p <host_port1>:<container_port1> -p <host_port2>:<container_port2>
您可以这样做:
docker run -d -p 49160:8080 -p 8888:8888 --name app localhost:5000/test/app
这篇关于Docker中的AngularJS和NodeJS应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!