如何 运行 OSX 上的 Bazel 容器镜像?

How to run Bazel container images on OSX?

根据 bazelbuild/rules_docker 上的文档,应该可以在 OSX 上使用这些容器映像,并且它还声称可以在没有 docker 的情况下这样做。

These rules do not require / use Docker for pulling, building, or pushing images. This means:

They can be used to develop Docker containers on Windows / OSX without boot2docker or docker-machine installed.
They do not require root access on your workstation.

我该怎么做?这是一个简单的规则:

go_image(
    name = "helloworld_image",
    importpath = "github.com/nictuku/helloworld",
    library = ":go_default_library",
    visibility = ["//visibility:public"],
)

我可以构建图像bazel build :helloworld_image。它在 blaze-bin 中产生了一个 tar 球,但它不会 运行 它:

INFO: Running command line: bazel-bin/helloworld_image
Loaded image ID: sha256:08d312b529d30431c68741fd3a31468a02533f27a8c2c29eedc969dae5a39852
Tagging 08d312b529d30431c68741fd3a31468a02533f27a8c2c29eedc969dae5a39852 as bazel:helloworld_image
standard_init_linux.go:185: exec user process caused "exec format error"
ERROR: Non-zero return code '1' from command: Process exited with status 1.

它试图 运行 linux 这是 OSX,这很愚蠢。

我也尝试对 .tar 内容进行 "docker load",但它似乎不喜欢那种格式。

$ docker 加载 -i bazel-bin/helloworld_image-layer.tar
打开 /var/lib/docker/tmp/docker-import-330829602/app/json: 没有那个文件或目录

帮忙?谢谢!

默认情况下,您正在为您的主机平台构建,因此如果您想这样做,您需要为容器平台构建。

由于你使用的是go binary,你可以通过在命令行指定--cpu=k8来进行交叉编译。理想情况下,我们可以说 docker 图像需要一个 linux 二进制文件(因此无需指定 --cpu 命令行标志)但这仍然是一项工作Bazel 的进展。