【问题标题】:When I hit https://<external IP>, I want to be able to access the application running on port 3000 on the container in GEC当我点击 https://<external IP> 时,我希望能够访问在 GEC 中容器的端口 3000 上运行的应用程序
【发布时间】:2020-10-11 02:17:10
【问题描述】:

我这样写了 Dockerfile,然后我将它推送到 GCP 上的 Container Registory

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:// 访问应用程序。我不知道该怎么办。

【问题讨论】:

    标签: node.js google-cloud-platform google-compute-engine nuxt.js


    【解决方案1】:

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

    如果您已经在注册表中拥有容器,您可以使用 gcloud 来部署它。这是一个例子:

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

    您可以通过运行gcloud config get-value project获取您的项目ID

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

    【讨论】:

    • 谢谢你的好建议。我执行gcloud run deploy --image gcr.io/PROJECT-ID/CONTAINER-ID --platform managed --port 3000,我得到了网址。我访问了应用程序网址。显示此错误。 Error: Forbidden Your client does not have permission to get URL / from this server.
    • 可能 run.services.setIamPolicy 不够。我去搜一下。
    • 将 --allow-unauthenticated 添加到您的部署命令。 Cloud Run 容器默认只允许经过身份验证的请求。
    猜你喜欢
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    • 2021-10-03
    相关资源
    最近更新 更多