无法将参数传递给 运行 Google 云中的 Docker 文件

Can't pass argument to Docker file in run Google Cloud

我一直在尝试在 google 云中获取 ENV 变量并将其注入到我的应用程序中。部署应用程序后,我无法理解或获得我想要的结果。我现在正在尝试将变量作为 ARG 注入到 DOCKER 文件中,但总是出错。

steps:
  - name: gcr.io/cloud-builders/docker
    args:
      - build
      - '--no-cache'
      - '--build-arg MONGO_URL=${_MONGO_URL}'
      - '-t'
      - '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
      - .
      - '-f'
      - Dockerfile
    id: Build

上面的代码是我的 YAML 文件,其中包含构建中的步骤。我有 --build-arg 命令。

ARG MONGO_URL

# Create app directory
WORKDIR /app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm ci
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

ENV GRAPHQL_URL=${GRAPHQL_URL}
ENV MONGO_URL=${MONGO_URL}

而且我希望我的 docker 文件中有一个 Arg,但随后出现此错误:

Step #0 - "Build": invalid argument "MONGO_URL=hola" for "-t, --tag" flag: invalid reference format: repository name must be lowercase

我发现我没有正确通过 --build-arg:

        steps:
  - name: gcr.io/cloud-builders/docker
    args:
      - build
      - '--no-cache'
      - '--build-arg' 
      - 'MONGO_URL=${_MONGO_URL}'
      - '-t'
      - '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
      - .
      - '-f'
      - Dockerfile
    id: Build