【问题标题】:Unable to build podman compatiable containers using nix-build and dockerTools.buildImage无法使用 nix-build 和 dockerTools.buildImage 构建 podman 兼容容器
【发布时间】:2022-10-16 22:48:34
【问题描述】:

以下是invidious.nix,它构建了一个包含 Bash、Busybox 和 Invidious 的 nix 包的容器:

let
  # nixos-22.05 / https://status.nixos.org/
  pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/d86a4619b7e80bddb6c01bc01a954f368c56d1df.tar.gz") {};
in rec {

  docker = pkgs.dockerTools.buildImage {
    name = "invidious";
    contents = [ pkgs.busybox pkgs.bash pkgs.invidious ];
    config = {
      Cmd = [ "/bin/bash" ];
      Env = [];
      Volumes = {};
    };
  };
}

如果我尝试使用docker load < result 加载容器,Docker 可以正确加载容器。

docker load < result
14508d34fd29: Loading layer [==================================================>]  156.6MB/156.6MB
Loaded image: invidious:2nrcdxgz46isccfgyzdcbirs0vvqhp55

但是,如果我使用 podman 尝试相同的操作,我会收到以下错误:

podman load < result
Error: payload does not match any of the supported image formats:
 * oci: initializing source oci:/var/tmp/podman3824611648:: open /var/tmp/podman3824611648/index.json: not a directory
 * oci-archive: loading index: open /var/tmp/oci1927542201/index.json: no such file or directory
 * docker-archive: loading tar component manifest.json: archive/tar: invalid tar header
 * dir: open /var/tmp/podman3824611648/manifest.json: not a directory

如果我检查结果,它似乎确实具有 OCI 容器的正确格式:

tar tvfz result
dr-xr-xr-x root/root         0 1979-12-31 19:00 ./
-r--r--r-- root/root       391 1979-12-31 19:00 027302622543ef251be6d3f2d616f98c73399d8cd074b0d1497e5a7da5e6c882.json
dr-xr-xr-x root/root         0 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/
-r--r--r-- root/root         3 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/VERSION
-r--r--r-- root/root       353 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/json
-r--r--r-- root/root 156579840 1979-12-31 19:00 669db3729b40e36a9153569b747788611e547f0b50a9f7d77107a04c6ddd887e/layer.tar
-r--r--r-- root/root       280 1979-12-31 19:00 manifest.json
-r--r--r-- root/root       128 1979-12-31 19:00 repositories

如何让nix-build 创建podman 可以读取的兼容容器?

nix-build 版本:2.10.3

播客版本:4.2.0

【问题讨论】:

  • nix-build -A nixosTests.podman 是否适用于您的 Nixpkgs 版本?你也可以试试buildLayeredImage 吗?
  • @RobertHensing 这是因为 podman 4.2.0 显然无法读取 gzip 容器。它只能加载焦油。请看下面我的回答。

标签: containers nix podman


【解决方案1】:

事实证明,我正在运行的 podman 版本无法读取 gzip 压缩的 tar 文件。以下作品:

zcat result | podman load

【讨论】:

    猜你喜欢
    • 2021-05-15
    • 2020-04-30
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    相关资源
    最近更新 更多