Cloud 运行 是否需要 NGINX?
Cloud Run needs NGINX or not?
我正在为我的博客和工作网站使用云 运行,我真的很喜欢它。
我已经根据 google 教程通过容器化部署了 python API 和 Vue/Nuxt 应用程序。
我不明白的一件事是为什么不需要在前面安装NGINX。
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12-slim
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install production dependencies.
RUN npm install --only=production
# Copy local code to the container image.
COPY . ./
# Run the web service on container startup.
RUN npm run build
CMD [ "npm", "start" ]
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc
RUN pip install -r requirements.txt
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn -b :$PORT --workers=4 main:server
所有这一切都在我没有调用 Nginx 的情况下工作。
但我读了很多文章,人们将 NGINX 捆绑在他们的容器中。所以我想澄清一下。我在做什么有什么缺点吗?
使用 NGINX 或静态文件服务器的一个相当大的优势是容器映像的大小。在为 SPA(没有 SSR)提供服务时,您只需将捆绑文件发送给客户端即可。无需捆绑编译应用程序所需的构建依赖项或运行时。
您的第一个映像是将具有依赖项的整个源代码复制到映像中,而您所需要的(如果不是 运行 SSR)是编译后的文件。 NGINX 可以为您提供 "static site server",它只会为您的构建服务,并且是一个轻量级解决方案。
关于python,除非你能以某种方式捆绑它,否则在没有 NGINX 的情况下使用它看起来没问题。
我正在为我的博客和工作网站使用云 运行,我真的很喜欢它。 我已经根据 google 教程通过容器化部署了 python API 和 Vue/Nuxt 应用程序。 我不明白的一件事是为什么不需要在前面安装NGINX。
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12-slim
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install production dependencies.
RUN npm install --only=production
# Copy local code to the container image.
COPY . ./
# Run the web service on container startup.
RUN npm run build
CMD [ "npm", "start" ]
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc
RUN pip install -r requirements.txt
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn -b :$PORT --workers=4 main:server
所有这一切都在我没有调用 Nginx 的情况下工作。 但我读了很多文章,人们将 NGINX 捆绑在他们的容器中。所以我想澄清一下。我在做什么有什么缺点吗?
使用 NGINX 或静态文件服务器的一个相当大的优势是容器映像的大小。在为 SPA(没有 SSR)提供服务时,您只需将捆绑文件发送给客户端即可。无需捆绑编译应用程序所需的构建依赖项或运行时。
您的第一个映像是将具有依赖项的整个源代码复制到映像中,而您所需要的(如果不是 运行 SSR)是编译后的文件。 NGINX 可以为您提供 "static site server",它只会为您的构建服务,并且是一个轻量级解决方案。
关于python,除非你能以某种方式捆绑它,否则在没有 NGINX 的情况下使用它看起来没问题。