如何编辑 GCP Cloud Run 添加映射到 /etc/hosts

San*_*tiG 5 docker google-cloud-platform google-cloud-run

我需要将服务名称映射到 IP,以便使应用程序正常工作
/etc/host 文件示例:

10.0.0.1 service-name
Run Code Online (Sandbox Code Playgroud)

但是尝试在 Dockerfile 构建期间编辑该文件会让我感到困惑

/bin/sh: can't create /etc/hosts: Read-only file system
Run Code Online (Sandbox Code Playgroud)

在 GCP Cloud Run YAML 中,不支持“HostAliases” 我无法在 GCP Cloud Run 中添加“--add-host”标志

有谁知道还有其他选项可以将服务名称映射到特定 IP 来修复我的 Cloud Run 应用程序吗?

Dockerfile

FROM node:16-alpine

VOLUME /tmp
# Create app directory
WORKDIR /usr/src/app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

COPY . .

# This are the lines that are not working
# And can't find any workaround in GCP Cloud Run
RUN echo 10.0.0.4   servicename-0 >> /etc/hosts
RUN echo 10.0.0.3   servicename-1 >> /etc/hosts

EXPOSE 3000
ARG NODE_ENV=production
CMD [ "npm", "run", "start:prod" ]
Run Code Online (Sandbox Code Playgroud)