microsoft / vscode-docker

Docker Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
Other
1.2k stars 512 forks source link

Compatibility with Podman 4.x #3812

Closed evanshortiss closed 1 year ago

evanshortiss commented 1 year ago

I've been trying to use this extension with Podman 4.3.1, but it seems incompatible. I can successfully use the Podman socket on my MacBook by setting

DOCKER_HOST=unix:///Users/$USER/.local/share/containers/podman/machine/podman-machine-default/podman.sock

and using the Docker CLI. However the extension shows no output as I set "docker.dockerPath": "/opt/podman/bin/podman" to use the Podman CLI.

I debugged the listImages() function, and narrowed the issue down. It seems like the Docker CLI outputs entries as line by line JSON objects, whereas Podman outputs an array of objects and results in a parsing error (in this function). I've included sample output from both at the bottom of this issue.

This might not be an issue for consideration for this plugin, since it's designed around Docker and perhaps Podman should match the Docker output.

Interestingly enough, using cURL to interact with the API (i.e curl --unix-socket /var/run/docker.sock 'http://localhost/images/json' and curl --unix-socket /Users/$USER/.local/share/containers/podman/machine/podman-machine-default/podman.sock 'http://localhost/images/json') of Podman/Docker produces more closely aligned output, though Podman's output is a tad more verbose.

Docker

docker image ls --filter dangling=false --no-trunc --format {{json .}}
{"Containers":"N/A","CreatedAt":"2023-01-18 02:19:32 -0800 PST","CreatedSince":"7 days ago","Digest":"\u003cnone\u003e","ID":"sha256:25b4f3c19d92ecdf2543660323e28c486c3bd3d163eb33f36284fdc390151273","Repository":"registry.access.redhat.com/ubi8/openjdk-17","SharedSize":"N/A","Size":"420MB","Tag":"1.14","UniqueSize":"N/A","VirtualSize":"419.6MB"}
{"Containers":"N/A","CreatedAt":"2023-01-17 13:26:02 -0800 PST","CreatedSince":"8 days ago","Digest":"\u003cnone\u003e","ID":"sha256:2030918f10e8371bb55240da2bf0b8dff52488c9ffaabdd164abd1052479e8e3","Repository":"redis","SharedSize":"N/A","Size":"30.3MB","Tag":"7-alpine","UniqueSize":"N/A","VirtualSize":"30.31MB"}
{"Containers":"N/A","CreatedAt":"2022-10-29 10:46:44 -0700 PDT","CreatedSince":"2 months ago","Digest":"\u003cnone\u003e","ID":"sha256:d3cc09b059e06f72a1f1351b0a003e6c490d4e4f80fc778befde2c7ac6e804d4","Repository":"quay.io/strimzi/kafka","SharedSize":"N/A","Size":"639MB","Tag":"0.32.0-kafka-3.3.1","UniqueSize":"N/A","VirtualSize":"639.2MB"}
{"Containers":"N/A","CreatedAt":"2022-07-28 07:12:30 -0700 PDT","CreatedSince":"6 months ago","Digest":"\u003cnone\u003e","ID":"sha256:5d28cedc492d64d21c11814d84d9d41566f07023b9c95245e163b05acfcb7172","Repository":"testcontainers/ryuk","SharedSize":"N/A","Size":"11.5MB","Tag":"0.3.4","UniqueSize":"N/A","VirtualSize":"11.48MB"}
{"Containers":"N/A","CreatedAt":"2021-11-03 15:51:58 -0700 PDT","CreatedSince":"14 months ago","Digest":"\u003cnone\u003e","ID":"sha256:5d0cbea9916f4e058267d6c2085aaa11fa75fe4780d735adce459bc79a6c40f1","Repository":"antora/antora","SharedSize":"N/A","Size":"95.7MB","Tag":"2.3.4","UniqueSize":"N/A","VirtualSize":"95.65MB"}

Podman

podman image ls --filter dangling=false --no-trunc --format {{json .}}
[
    {
        "Id": "5f3b9471a65d9cbe70f41f5e46a7f2c8672709556e444ed148d023f89ec74ca7",
        "ParentId": "fedee2f8f2089adbe996e19e802797df236ff4ad9c674d4e5f4e011ca7795ab1",
        "RepoTags": null,
        "RepoDigests": [
            "registry.access.redhat.com/ubi8/openjdk-17@sha256:28f11d44f9613cff70108bdb4083aa46cad0faff199758f761bf62a34cb50e8a",
            "registry.access.redhat.com/ubi8/openjdk-17@sha256:6b536eec3bbf1e795d61a49ec7b5a80687fb5890d7e961ae0ddab672b8aaed54"
        ],
        "Size": 423383289,
        "SharedSize": 0,
        "VirtualSize": 423383289,
        "Labels": {
            "architecture": "arm64",
            "build-date": "2022-10-11T19:59:01.009662",
            "com.redhat.build-host": "arm-003.osbs.prod.upshift.rdu2.redhat.com",
            "com.redhat.component": "openjdk-17-ubi8-container",
            "com.redhat.license_terms": "https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI",
            "description": "Source To Image (S2I) image for Red Hat OpenShift providing OpenJDK 17",
        },
        "Containers": 0,
        "Names": [
            "registry.access.redhat.com/ubi8/openjdk-17:1.14"
        ],
        "Digest": "sha256:28f11d44f9613cff70108bdb4083aa46cad0faff199758f761bf62a34cb50e8a",
        "History": [
            "registry.access.redhat.com/ubi8/openjdk-17:1.14"
        ],
        "Created": 1665520470,
        "CreatedAt": "2022-10-11T20:34:30Z"
    }
]
evanshortiss commented 1 year ago

Podman 4.4 might fix this. I will test when I get the chance.

bwateratmsft commented 1 year ago

I'm going to dupe this to #3241. Podman's CLI is incompatible with Docker's in a few ways, enough that it's not sufficient to just change docker.dockerPath. We're working on a solution to properly support Podman.

evanshortiss commented 1 year ago

@bwateratmsft thanks. It sounds like Podman 4.4 might help based on this comment

bwateratmsft commented 1 year ago

TBH I'd have preferred Podman keep its format as-is, since it's actually syntactically correct JSON. Parsing the output from the Docker CLI is made much harder by all the deviation it does 😕 (e.g. one-object-per-line instead of an array, labels and similar things being smushed down into a string instead of a nested object, etc.)

evanshortiss commented 1 year ago

Yeah, I was kind of surprised by the Docker output TBH. Podman's makes much more sense, though I guess it'd be unlikely Docker will change their format at this stage.

gjbianco commented 1 year ago

I was confused by the Docker output as well, but the description of the associated Podman PR makes the line-delimited Docker output seem sensible.

i.e. the difference between "give me the results in JSON format" vs "format each result as JSON".

evanshortiss commented 1 year ago

True. A command using table with a format string is technically line by line too: podman images --format 'table {{.Tag}}'. We'll allow it 😉