nix2container icon indicating copy to clipboard operation
nix2container copied to clipboard

podman example in README doesn't quite work

Open CyberShadow opened this issue 1 year ago • 4 comments

$ nix --extra-experimental-features nix-command --extra-experimental-features flakes run github:nlewo/nix2container#examples.bash.copyToPodman
                                                                                                                                                                             
Copy to podman image bash:k8g30kq8xhw50pd9ch321md9n2cylppw
Getting image source signatures
Copying blob a546c70d96cd skipped: already exists  
Copying config 7202af4391 done  
Writing manifest to image destination
Storing signatures
{
    "Name": "docker.io/library/bash",
    "Digest": "sha256:517f33e35f1c73b81c94d231e363155d10ad24d9f8f06f47071b271315db4f9b",
    "RepoTags": [],
    "Created": null,
    "DockerVersion": "",
    "Labels": null,
    "Architecture": "amd64",
    "Os": "linux",
    "Layers": [
        "sha256:a546c70d96cd7c28b43e0effee39c7b1e102e5d52dda968a14975972f85304f5"
    ],
    "LayersData": [
        {
            "MIMEType": "application/vnd.oci.image.layer.v1.tar",
            "Digest": "sha256:a546c70d96cd7c28b43e0effee39c7b1e102e5d52dda968a14975972f85304f5",
            "Size": 56502272,
            "Annotations": null
        }
    ],
    "Env": null
}

$ podman run -it --rm bash                  
Error: short-name "bash" did not resolve to an alias and no unqualified-search registries are defined in "/etc/containers/registries.conf"

$ podman run -it --rm docker.io/library/bash
Trying to pull docker.io/library/bash:latest...
^C
$ podman run -it --rm docker.io/library/bash@sha256:517f33e35f1c73b81c94d231e363155d10ad24d9f8f06f47071b271315db4f9b
bash-5.2#                                                                                                                                          

Sorry I'm not very familiar with nix, but I don't see even how to get the @sha256:... hash automatically. I think something like docker build's --iidfile would be nice?

CyberShadow avatar Jun 24 '23 14:06 CyberShadow

Correct, this example is not correct because the image tag is not latest as you can see in the copyToPodman logs:

Copy to podman image bash:k8g30kq8xhw50pd9ch321md9n2cylppw

So, currently, you would have to run:

podman run bash:k8g30kq8xhw50pd9ch321md9n2cylppw

nlewo avatar Jun 25 '23 06:06 nlewo

Thanks, is there a good way to get the k8g30kq8xhw50pd9ch321md9n2cylppw tag programmatically?

CyberShadow avatar Jun 27 '23 06:06 CyberShadow

Thanks, is there a good way to get the k8g30kq8xhw50pd9ch321md9n2cylppw tag programmatically?

Sure, this is the hash of the Nix derivation and you can even get it without having to build the image! For instance:

nix eval --impure --expr 'let f = builtins.getFlake "github:nlewo/nix2container"; in f.packages.x86_64-linux.examples.bash.imageTag'

You can also find some examples in the tests directory.

(Note: i still need to update this example in the README.)

nlewo avatar Jun 27 '23 06:06 nlewo

I can't get the podman example to work.

$ podman image ls --all
REPOSITORY                                      TAG                               IMAGE ID      CREATED       SIZE

$ nix run github:nlewo/nix2container#examples.bash.copyToPodman
Copy to podman image bash:4ym1c6xhcd5mpl19p2b0phssppb4idam
INFO[0000] Image operating system mismatch: image uses OS "linux"+architecture "arm64", expecting one of "darwin+arm64"
Getting image source signatures
Copying blob 1238ad9d83ec skipped: already exists
Copying config 7b1fac7a38 done
Writing manifest to image destination
{
    "Name": "docker.io/library/bash",
    "Digest": "sha256:2828fc84c89dcc6060f124793297e20162eece3b301536d1b10b4802ef3ec2ea",
    "RepoTags": [],
    "Created": null,
    "DockerVersion": "",
    "Labels": null,
    "Architecture": "arm64",
    "Os": "linux",
    "Layers": [
        "sha256:1238ad9d83ec88810509e8aeb2b106498a0cb5b3030fb096f627dafdecf9b713"
    ],
    "LayersData": [
        {
            "MIMEType": "application/vnd.oci.image.layer.v1.tar",
            "Digest": "sha256:1238ad9d83ec88810509e8aeb2b106498a0cb5b3030fb096f627dafdecf9b713",
            "Size": 18597888,
            "Annotations": null
        }
    ],
    "Env": null
}

$ podman image ls --all
REPOSITORY                                      TAG                               IMAGE ID      CREATED       SIZE

$ podman run --pull never --rm bash
Error: bash: image not known

$ podman run --pull never --rm bash:4ym1c6xhcd5mpl19p2b0phssppb4idam
Error: bash:4ym1c6xhcd5mpl19p2b0phssppb4idam: image not known

$ podman run --pull never --rm docker.io/library/bash@sha256:2828fc84c89dcc6060f124793297e20162eece3b301536d1b10b4802ef3ec2ea
Error: docker.io/library/bash@sha256:2828fc84c89dcc6060f124793297e20162eece3b301536d1b10b4802ef3ec2ea: image not known

schradert avatar Apr 02 '24 00:04 schradert