当我点击 https://<external IP> 时,我希望能够访问 GEC 容器上的端口 3000 上的应用程序 运行

When I hit https://<external IP>, I want to be able to access the application running on port 3000 on the container in GEC

我这样写了 Dockerfile 并将其推送到 GCP 上的 Container Registry

FROM node:13.12.0-alpine as builder

RUN mkdir -p /usr/src/nuxt-app 
WORKDIR /usr/src/nuxt-app

RUN apk update && apk upgrade
RUN apk add --update --no-cache python make g++
COPY . /usr/src/nuxt-app
RUN rm -rf ./node_modules && npm install
RUN npm run build

EXPOSE 3000

ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
ARG API_ENDPOINT
ENV API_ENDPOINT $API_ENDPOINT

CMD [ "npm", "start" ]

我在 gce 实例上部署了 docekr 映像。我可以使用 http://:3000 访问应用程序。但我最终想做的是使用 https:// 访问应用程序。我不知道该怎么做。

如果您只想要一种 运行 容器的简单方法并向其发送 HTTPS 请求,您可以部署在云 运行 而不是 GCE 上。您的问题是您只是 运行 一个 HTTP 服务器,对于 HTTPS,您至少需要为您的服务器添加一个证书和匹配的 DNS 名称。 Cloud 运行 是一种更高抽象级别的服务,可以为您做到这一点。显然,您也可以使用 GCE 以多种方式完成它,但它会涉及更多。

如果注册表中已有容器,则可以使用 gcloud 部署容器。这是一个例子:

gcloud run deploy --image gcr.io/PROJECT-ID/CONTAINER-ID --platform managed --port 3000

您可以通过 运行 gcloud config get-value project

获取您的项目 ID

这是 Cloud 运行 的完整快速入门:https://cloud.google.com/run/docs/quickstarts/build-and-deploy