【问题标题】:Can't pass argument to Docker file in run Google Cloud无法在运行 Google Cloud 时将参数传递给 Docker 文件
【发布时间】:2022-01-31 18:33:57
【问题描述】:

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

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 cmd。

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

【问题讨论】:

    标签: docker google-cloud-platform yaml environment-variables


    【解决方案1】:

    我发现我没有正确传递 --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
    

    【讨论】:

      猜你喜欢
      • 2021-09-24
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 2016-09-15
      • 2020-06-23
      相关资源
      最近更新 更多