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

podman container ls --format="{{.State}}" returns the wrong information #18244

Closed
mdhirt opened this issue Apr 18, 2023 · 7 comments · Fixed by #18320
Closed

podman container ls --format="{{.State}}" returns the wrong information #18244

mdhirt opened this issue Apr 18, 2023 · 7 comments · Fixed by #18320
Assignees
Labels
bugweek Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@mdhirt
Copy link

mdhirt commented Apr 18, 2023

Podman version 4.1.1 on RedHat 8.5

Specifying a format to include container State in the output of podman container ls returns the value from the Status field and not the State field.

Actual Result.
podman container ls -a --format="{{json .Names}} {{json .State}} {{json .Status}}"
"test-container" "Up 3 weeks ago" "Up 3 weeks ago"
"stopped-container" "Exited (0) 16 Seconds ago" "Exited (0) 16 Seconds ago"

Expected Result.
podman container ls --format="{{json .Names}} {{json .State}} {{json .Status}}"
"test-container" "running" "Up 3 weeks ago"
"stopped-container" "exited" "Exited (0) 16 seconds ago"

Additional information.
Running podman container ls --format=json does display the correct state=value, however when scripting automated health checks it is useful to limit the returned values using the --filter="{{ }}" option.
podman container ls --format=json
[
{
...
"Names": [
"test-container"
],
...
"State": "running"
"Status": "Up 3 weeks ago"
...
},
{
...
"Names": [
"stopped-container"
],
...
"State": "exited"
"Status": "Exited (0) 16 seconds ago"
...
}
]

@vrothberg
Copy link
Member

Thanks for reaching out, @mdhirt!

Since you mention running on RHEL. If you desire a backport to RHEL, please reach out through the Red Hat customer channels. We can fix it upstream but downstream is up to the individual distributions/vendors.

@Luap99
Copy link
Member

Luap99 commented Apr 18, 2023

--format "{{.ListContainer.State}}" should result in the output you want

@mdhirt
Copy link
Author

mdhirt commented Apr 20, 2023

Thank you @Luap99 this provides exactly what I need.

Should I close this issue now or is it still a bug that .State and .Status both return the output for .Status?

@Luap99
Copy link
Member

Luap99 commented Apr 21, 2023

I don't know, looking at the code history podman has this behavior at least since v2.0. So far nobody complained, changing the output now could break existing users that want the current output. Although we try to be docker compatible, if this works with docker it is a valid reason for us to change it.

@vrothberg
Copy link
Member

I don't know, looking at the code history podman has this behavior at least since v2.0. So far nobody complained, changing the output now could break existing users that want the current output. Although we try to be docker compatible, if this works with docker it is a valid reason for us to change it.

It works with Docker, so I think we should change it.

@rhatdan
Copy link
Member

rhatdan commented Apr 21, 2023

I agree.

@rhatdan rhatdan added bugweek Good First Issue This issue would be a good issue for a first time contributor to undertake. labels Apr 21, 2023
@Luap99 Luap99 added the kind/bug Categorizes issue or PR as related to a bug. label Apr 21, 2023
@baude
Copy link
Member

baude commented Apr 23, 2023

@jwhonce do you recall any history on this one by chance?

@Luap99 Luap99 self-assigned this Apr 24, 2023
Luap99 added a commit to Luap99/libpod that referenced this issue Apr 24, 2023
We should return the raw state string without any extra formatting in
this case.
`{{.Status}}` returns the nicely formatted string used in the default ps
output, e.g. `Up 2 seconds ago`, while `{{.State}}` returns the state as
string, e.g. `running`.

This matches the docker output and allows better use in scripts.

Fixes containers#18244

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Luap99 added a commit to Luap99/libpod that referenced this issue Apr 24, 2023
We should return the raw state string without any extra formatting in
this case.
`{{.Status}}` returns the nicely formatted string used in the default ps
output, e.g. `Up 2 seconds ago`, while `{{.State}}` returns the state as
string, e.g. `running`.

This matches the docker output and allows better use in scripts.

Fixes containers#18244

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
@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 Aug 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugweek Good First Issue This issue would be a good issue for a first time contributor to undertake. kind/bug Categorizes issue or PR as related to a bug. 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.

5 participants