Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support podman version --format '{{ json . }}' for docker compatibility #2671

Closed
wjt opened this issue Mar 15, 2019 · 13 comments · Fixed by #2688
Closed

Support podman version --format '{{ json . }}' for docker compatibility #2671

wjt opened this issue Mar 15, 2019 · 13 comments · Fixed by #2688
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@wjt
Copy link
Contributor

wjt commented Mar 15, 2019

/kind feature

Description

I tried to use Karton (which uses the docker CLI) with docker as a symlink to podman. I failed at the first hurdle because it tries to run docker version --format '{{ json . }}', which fails:

$ podman version --format '{{ json . }}'
Error: template parsing error: template: image:1: function "json" not defined

podman version --format json works, but produces output like this:

$ podman version --format json
{
    "RemoteAPIVersion": 1,
    "Version": "1.0.1-dev",
    "GoVersion": "go1.11.5",
    "GitCommit": "",
    "Built": 0,
    "OsArch": "linux/amd64"
}

Whereas according to the Docker documentation, Docker produces differently-formatted output:

$ docker version --format '{{json .}}'

{"Client":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"},"ServerOK":true,"Server":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","KernelVersion":"3.13.2-gentoo","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"}}

I'm calling this a feature request, but depending on the policy on docker CLI compatibility, maybe it's a bug. (Arguably I should just teach Karton about podman.)

Steps to reproduce the issue:

  1. Run podman version --format '{{json .}}'

Describe the results you received:

Error: template parsing error: template: image:1: function "json" not defined

Describe the results you expected:

Output of the same shape as docker version --format '{{json .}}'.

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

Version:            1.0.1-dev
RemoteAPI Version:  1
Go Version:         go1.11.5
OS/Arch:            linux/amd64

Output of podman info --debug:

debug:
  compiler: gc
  git commit: ""
  go version: go1.11.5
  podman version: 1.0.1-dev
host:
  BuildahVersion: 1.7-dev
  Conmon:
    package: 'cri-o-1.12: /usr/lib/crio/bin/conmon'
    path: /usr/lib/crio/bin/conmon
    version: 'conmon version 1.12.4-dev, commit: '
  Distribution:
    distribution: '"endless"'
    version: 3.6.0
  MemFree: 4667650048
  MemTotal: 8262066176
  OCIRuntime:
    package: 'cri-o-runc: /usr/sbin/runc'
    path: /usr/sbin/runc
    version: 'runc version spec: 1.0.1-dev'
  SwapFree: 12393095168
  SwapTotal: 12393095168
  arch: amd64
  cpus: 4
  hostname: tensionsheet-redux
  kernel: 4.20.0-2-generic
  os: linux
  rootless: true
  uptime: 14m 31.45s
insecure registries:
  registries: []
registries:
  registries:
  - docker.io
  - registry.fedoraproject.org
  - quay.io
  - registry.access.redhat.com
  - registry.centos.org
store:
  ConfigFile: /sysroot/home/wjt/.config/containers/storage.conf
  ContainerStore:
    number: 0
  GraphDriverName: vfs
  GraphOptions: null
  GraphRoot: /sysroot/home/wjt/.local/share/containers/storage
  GraphStatus: {}
  ImageStore:
    number: 0
  RunRoot: /run/user/1001
debug:
  compiler: gc
  git commit: ""
  go version: go1.11.5
  podman version: 1.0.1-dev
host:
  BuildahVersion: 1.7-dev
  Conmon:
    package: 'cri-o-1.12: /usr/lib/crio/bin/conmon'
    path: /usr/lib/crio/bin/conmon
    version: 'conmon version 1.12.4-dev, commit: '
  Distribution:
    distribution: '"endless"'
    version: 3.6.0
  MemFree: 4667650048
  MemTotal: 8262066176
  OCIRuntime:
    package: 'cri-o-runc: /usr/sbin/runc'
    path: /usr/sbin/runc
    version: 'runc version spec: 1.0.1-dev'
  SwapFree: 12393095168
  SwapTotal: 12393095168
  arch: amd64
  cpus: 4
  hostname: tensionsheet-redux
  kernel: 4.20.0-2-generic
  os: linux
  rootless: true
  uptime: 14m 31.45s
insecure registries:
  registries: []
registries:
  registries:
  - docker.io
  - registry.fedoraproject.org
  - quay.io
  - registry.access.redhat.com
  - registry.centos.org
store:
  ConfigFile: /sysroot/home/wjt/.config/containers/storage.conf
  ContainerStore:
    number: 0
  GraphDriverName: vfs
  GraphOptions: null
  GraphRoot: /sysroot/home/wjt/.local/share/containers/storage
  GraphStatus: {}
  ImageStore:
    number: 0
  RunRoot: /run/user/1001

Additional environment details (AWS, VirtualBox, physical, etc.):

I'm using the development branch of Endless OS, which as of 24 hours ago include podman.

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 15, 2019
wjt added a commit to wjt/karton that referenced this issue Mar 15, 2019
`podman` is an almost-CLI-compatible replacement for `docker`, which
allows unprivileged users to run containers, with no daemon. On some
systems, `docker` is a symbolic link to `podman`.

I say "almost" because one command that is not compatible is `docker
version --format '{{ json . }}'`, used by Karton to detect whether
docker is present and usable.
containers/podman#2671

To work around this, if _try_docker() fails, but running `podman
version` succeeds, use `podman` instead. Otherwise, behave as before.
@baude
Copy link
Member

baude commented Mar 15, 2019

on most of our comments where format is offered, you can pass --format json ... not the absence of go templating.

@mheon
Copy link
Member

mheon commented Mar 15, 2019

I don't know how much sense mimicing docker version format here makes - we don't have a server, so the client and server split doesn't make any sense. Adding some of the missing information might be a good idea, though I think we print most of that in podman info

@rhatdan
Copy link
Member

rhatdan commented Mar 16, 2019

Can't we support
podman version --format '{{ json . }}'

@rhatdan
Copy link
Member

rhatdan commented Mar 16, 2019

If you remove the json it works.
podman version --format '{{ . }}

@baude
Copy link
Member

baude commented Mar 17, 2019

yeah this can be done I think ... @rhatdan if you want me to kick this out, assign this to me and I'll assume that means you want it done.

@mheon
Copy link
Member

mheon commented Mar 17, 2019 via email

@wjt
Copy link
Contributor Author

wjt commented Mar 17, 2019

@baude IMO if we do this, we add the .json Go template, but we don't try and match the Docker JSON output, we just output the JSON we normally would for version.

FWIW Karton, the tool I was trying to use with podman, explicitly checks for the "Client" and "Server" keys so would have still failed in this case.

https://github.com/karton/karton/blob/5a9c46a5590923a7a9a77a05b9f90a234431bcc3/karton/dockerctl.py#L77-L82

@baude
Copy link
Member

baude commented Mar 17, 2019

@mheon agree but again, if it is no help due to the keys, then ...

@rhatdan
Copy link
Member

rhatdan commented Mar 18, 2019

@baude I think we should support it. But we really can not support the Client/Server keys since they make no sense for Podman.
@wjt WDYT?

@wjt
Copy link
Contributor Author

wjt commented Mar 18, 2019

I understand that the keys don't make sense for Podman; I guess there comes a point where it cannot be an absolutely 100% CLI-compatible drop-in replacement for Docker.

I wrote a small patch to make karton check for podman if docker version --format '{{ json . }} fails, and use it if found; I could equally well make it check whether the returned JSON indicates that docker is actually podman (if "Client" and/or "Server" are not present). I have no idea how many other tools might be parsing this JSON; perhaps the answer is 0 😄

@rhatdan
Copy link
Member

rhatdan commented Mar 18, 2019

Well we can only go so far before it starts lying. Podman is not a client/server application, so adding these fields makes no sense.

baude added a commit to baude/podman that referenced this issue Mar 18, 2019
for podman version, we now support a GO template for json output.

fixes containers#2671

Signed-off-by: baude <bbaude@redhat.com>
wjt added a commit to wjt/karton that referenced this issue Apr 30, 2019
`podman` is an almost-CLI-compatible replacement for `docker`, which
allows unprivileged users to run containers, with no daemon. On some
systems, `docker` is a symbolic link to `podman`.

I say "almost" because one command that is not compatible is `docker
version --format '{{ json . }}'`, used by Karton to detect whether
docker is present and usable.
containers/podman#2671

To work around this, if _try_docker() fails, but running `podman
version` succeeds, use `podman` instead. Otherwise, behave as before.
barisione pushed a commit to karton/karton that referenced this issue May 1, 2019
`podman` is an almost-CLI-compatible replacement for `docker`, which
allows unprivileged users to run containers, with no daemon. On some
systems, `docker` is a symbolic link to `podman`.

I say "almost" because one command that is not compatible is `docker
version --format '{{ json . }}'`, used by Karton to detect whether
docker is present and usable.
containers/podman#2671

To work around this, if _try_docker() fails, but running `podman
version` succeeds, use `podman` instead. Otherwise, behave as before.
@christian-korneck
Copy link

Podman is not a client/server application, so adding these fields makes no sense.

as podman is now a client/server app, does this still stand? (Noticed this docker/podman cli difference when trying to use podman-remote for vscode devcontainers [1] [2])

@rhatdan
Copy link
Member

rhatdan commented Mar 22, 2021

When run in remote mode, it does show that data, but not in local mode.

podman --remote version --format json
{"Client":{"APIVersion":"3.0.0","Version":"3.0.1","GoVersion":"go1.16","GitCommit":"","BuiltTime":"Mon Feb 22 09:08:57 2021","Built":1614002937,"OsArch":"linux/amd64"},"Server":{"APIVersion":"3.0.0","Version":"3.0.1","GoVersion":"go1.16","GitCommit":"","BuiltTime":"Mon Feb 22 09:08:57 2021","Built":1614002937,"OsArch":"linux/amd64"}}

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants