2

我有一个基本映像(名为@release_docker//image),我正在尝试在其上安装一些 apt 包(以及我构建的二进制文件)。这是它的样子:

load("@io_bazel_rules_docker//docker/package_managers:download_pkgs.bzl", "download_pkgs")
load("@io_bazel_rules_docker//docker/package_managers:install_pkgs.bzl", "install_pkgs")

download_pkgs(
    name = "downloaded-packages",
    image_tar = "@release_docker//image",
    packages = [
        "numactl",
        "pciutils",
        "python",
    ],
)

install_pkgs(
    name = "installed-packages",
    image_tar = "@release_docker//image",
    installables_tar = ":downloaded-packages.tar",
    output_image_name = "release_docker_with_packages"
)

cc_image(
    name = "my-image",
    base = ":installed-packages",
    binary = ":built-binary",
)

但是在构建 docker(运行构建命令的 docker 映像)内部,当我运行时bazel build :my-image --action_env DOCKER_HOST=tcp://192.168.1.2:2375,它会出错:

+ DOCKER=/usr/bin/docker
+ [[ -z /usr/bin/docker ]]
+ TO_JSON_TOOL=bazel-out/host/bin/external/io_bazel_rules_docker/docker/util/to_json
+ source external/io_bazel_rules_docker/docker/util/image_util.sh
++ bazel-out/host/bin/external/io_bazel_rules_docker/contrib/extract_image_id bazel-out/k8-fastbuild/bin/external/release_docker/image/image.tar
+ image_id=b55375fc9c651e1eff0428490d01b4883de0fca62b5b18e8ede9f3d812b3fc10
+ /usr/bin/docker load -i bazel-out/k8-fastbuild/bin/external/release_docker/image/image.tar
+++ pwd
+++ pwd
++ /usr/bin/docker run -d -v /opt/bazel-root-directory/...[path-to].../downloaded-packages.tar:/tmp/bazel-out/k8-fastbuild/bin/marzban/downloaded-packages.tar -v /opt/bazel-root-directory/...[path-to].../installed-packages.install:/tmp/installer.sh --privileged b55375fc9c651e1eff0428490d01b4883de0fca62b5b18e8ede9f3d812b3fc10 /tmp/installer.sh
/usr/bin/docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/tmp/installer.sh\": permission denied": unknown.
+ cid=ce62e444aefe1f32a20575750a6ee1cc9c2f79d46f2f60187a8bc23f87b5aa25
4

2 回答 2

0

我遇到了同样的问题,我花了一些时间才找到真正的原因。

正如您猜想的那样,您的rules_dockerrepo 版本中有一个错误。实际问题是假设本地文件夹可以直接挂载到目标映像中。显然,在 DIND(Docker-In-Docker)的情况下,假设失败了。

幸运的是,作为 install_pkgs 的一部分,此错误已被修复,它使用命名卷与 DIND 一起工作。正如标题所示,解决方案是使用命名卷而不是 short -v src:dst

因此,解决方案是升级到 v0.13.0 或更高版本。

 rules_docker$ git tag --contains 32f12766248bef88358fc1646a3e0a66efd0e502 | head -1
v0.13.0

于 2020-06-02T10:45:53.253 回答
-1

我遇到了和你完全相同的问题。如果您将 '"@release_docker//image"' 更改为 ""@release_docker//image:image.tar" 它应该可以工作。

该规则需要一个 .tar 文件(与 docker save imageName 格式相同)。我没有查看规则背后的代码,但我认为图像也需要访问 apt。

这是一个工作示例

构建文件

load(
    "@io_bazel_rules_docker//docker/package_managers:download_pkgs.bzl",
    "download_pkgs",
)
load(
    "@io_bazel_rules_docker//docker/package_managers:install_pkgs.bzl",
    "install_pkgs",
)

install_pkgs(
    name = "postgresPythonImage",
    image_tar = "@py3_image_base//image:image.tar",
    installables_tar = ":postgresql_pkgs.tar",
    output_image_name = "postgres_python_base"
)

download_pkgs(
    name = "postgresql_pkgs",
    image_tar = "@ubuntu1604//image:image.tar",
    packages = [
        "postgresql"
    ],
)

工作空间

http_archive(
    name = "layer_definitions",
    strip_prefix = "layer-definitions-ade30bae7cb1a8c1fed70e18040936fad75de8a3",
    urls = ["https://github.com/GoogleCloudPlatform/layer-definitions/archive/ade30bae7cb1a8c1fed70e18040936fad75de8a3.tar.gz"],
    sha256 = "af72a1a804934ba154c97c43429ec556eeaadac70336f614ac123b7f5a5db299"
)

load("@layer_definitions//layers/ubuntu1604/base:deps.bzl", ubuntu1604_base_deps = "deps")
ubuntu1604_base_deps()
于 2019-12-31T17:46:01.883 回答