【问题标题】:How do I set the build output platform x86_64 in a Skaffold configuration?如何在 Skaffold 配置中设置构建输出平台 x86_64?
【发布时间】:2021-11-09 11:50:44
【问题描述】:

由于我在 M1 mac 上进行开发,我的 Docker 构建将构建 ARM。我想构建 x86_64 图像,我知道我可以使用 --platform 标志构建它,但我想使用我的 Skaffold 配置来做到这一点。

【问题讨论】:

    标签: kubernetes skaffold


    【解决方案1】:

    感谢@p10l 让我走上了正确的道路,我能够弄明白。 Skaffold 无法使用 Docker Engine API 设置平台,因此我们需要将 useDockerCLI 设置为 true 并将 cliFlags 添加到我们的 Docker 配置中,从而将 --platform=linux/x86_64 传递到命令行。

    apiVersion: skaffold/v2beta26
    kind: Config
    build:
      # ... other unrelated config ...
      artifacts:
        - image: my-image
          context: ./
          docker:
            cliFlags:
              - --platform=linux/x86_64 
      local:
        useDockerCLI: true # the only way to set platform is with cliFlags so we need to enable the Docker CLI
    

    【讨论】:

    • 在 m1 mac 上对我来说也很有吸引力 - 没有复杂的配置等。也可以在涉及 helm 的情况下使用。谢谢
    【解决方案2】:

    Skaffold 具有 buildCommand 字段,您可以将自定义脚本传递到该字段。
    所以,例如

    ...
    build:
      artifacts:
      - image: "foo"
        context: .
        custom:
          buildCommand: ./build.sh
    ...
    

    build.sh

    docker buildx build \
      --platform linux/amd64
      ... # any other flags
    

    免责声明:以下所有内容均为推测。我目前无法对此进行测试,但如果我错了,我相信有人会纠正我。

    还有build.artifacts.docker 字段(目前处于测试阶段)。可以使用此字段将参数传递给 Docker 构建。

    ...
    build:
      artifacts:
      - image: "foo"
        context: .
        docker:
          dockerfile: <Dockerfile relative to workspace>
          target: <Dockerfile target name to build>
          buildArgs:
            platform: linux/amd64
      local:
        useDockerCLI: true #this is needed to use docker build CLI rather than Docker Engine API
    

    可能还需要将buildx 设置为Docker 的默认构建器。这可以通过

    来实现
    docker buildx install
    

    【讨论】:

    • 感谢您的回答!我还没有时间尝试,但我会在接下来的几天内完成
    猜你喜欢
    • 2022-01-10
    • 2021-06-16
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 2018-06-14
    相关资源
    最近更新 更多