Skip to content

Add .IPAddresses as formatting option on docker ps #2733

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Sep 21, 2020

fixes moby/moby#8786

This allows showing the IP address for each network that the container is attached to,
for example:

docker network create foo
docker run -d --name foo nginx:alpine
docker network connect foo foo

docker container ls --format 'table {{.ID}}\\t{{join .IPAddresses ", "}}'
CONTAINER ID   IP ADDRESSES
17e7d1910fc0   bridge:172.17.0.2, foo:172.19.0.2

docker container ls --format='{{json .IPAddresses}}' | jq .
[
  "bridge:172.17.0.2",
  "foo:172.19.0.2"
]

- Description for the changelog

@thaJeztah
Copy link
Member Author

Had this branch on my computer; not sure if we should merge (see discussion on moby/moby#8786), but thought to at least push it to github 😂

@thaJeztah thaJeztah force-pushed the ps_ip_address_details branch from d5ebad2 to 72a56bd Compare September 22, 2020 14:03
This allows showing the IP address for each network that the container is attached to,
for example:

    docker network create foo
    docker run -d --name foo nginx:alpine
    docker network connect foo foo

    container container ls --format 'table {{.ID}}\\t{{join .IPAddresses ", "}}'
    CONTAINER ID   IP ADDRESSES
    17e7d1910fc0   bridge:172.17.0.2, foo:172.19.0.2

    container container ls --format='{{json .IPAddresses}}' | jq .
    [
      "bridge:172.17.0.2",
      "foo:172.19.0.2"
    ]

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the ps_ip_address_details branch from 72a56bd to d24907b Compare March 30, 2022 19:25
@codecat
Copy link

codecat commented May 10, 2022

Are there any blockers (unrelated to Moby) to get this PR merged into Docker CLI? I think this would make the --format option for docker ps a lot more powerful.

Copy link
Contributor

@ndeloof ndeloof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I don't understand the need for ps command uses an intermediate ContainerContext type and not just expose the plain types.Container returned by the API for formatting

@thaJeztah
Copy link
Member Author

I want to have another look at this (also taking into account IPv6 addresses); slightly wondering if the <network-name>:<ip address> is the right / most usable format.

I don't understand the need for ps command uses an intermediate ContainerContext type and not just expose the plain types.Container returned by the API for formatting

I think this was done to decorate the struct with formatting functions (such as this one); the formatting is meant for "printing on the CLI", and is kinda separate from both "client" and "api", so may not be very suitable for inclusion in the upstream moby repository (as part of the types)

@ndeloof
Copy link
Contributor

ndeloof commented May 11, 2022

right, I've been confused by the naming used on ContainerContext. Would have used ContainerDecorator or something like this, Context doesn't make any sense to me here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: show container IP address with docker ps command
5 participants