【发布时间】:2016-04-19 22:10:12
【问题描述】:
我们有一个前端应用程序。 它是用 Angular (html + css + javascript) 编写的,需要由网络服务器 (nginx) 托管。 Angular 正在与 NodeJs 服务器进行通信,该服务器将与后端进行通信。
现在我们必须在 Docker 中运行它。
- 我们要使用 2 个 Docker 容器:一个使用 nodejs,一个使用 nginx,让它们一起工作
那么是否可以在一个存储库中写入 2 个 dockerfile? 主要思想是为 nodejs 提供 1 个 dockerfile,它也在运行 bower install、npm install、... 看起来像这样:
# Create app directory
RUN mkdir -p /usr/src/www
WORKDIR /usr/src/www
RUN npm install -g bower
RUN npm install -g gulp
# Install app dependencies
COPY . /usr/src/www/
RUN bower install
RUN npm install
RUN gulp build
EXPOSE port
CMD [ "node", "server.js" ]
还有一个 dockerfile,我们在其中运行 nginx-webserver,但也包含一个 nginx.conf,因此它可以指向我们的 node.js-container 中的正确 /dist 文件夹 nginx 的 dockerfile 会是这样的:
# Set nginx base image
FROM nginx
# Copy custom configuration file from the current directory
COPY nginx.conf /etc/nginx/nginx.conf
nginx.conf 的一个例子
location ~* /dist {
proxy_pass http://nodejs:port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
【问题讨论】:
-
有人可以确认这是否是正确的方法吗?
标签: angularjs node.js nginx docker