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

docker-compose ps should show port ranges as docker ps does #6910

Closed
neale-bpm opened this issue Sep 23, 2019 · 16 comments
Closed

docker-compose ps should show port ranges as docker ps does #6910

neale-bpm opened this issue Sep 23, 2019 · 16 comments
Labels

Comments

@neale-bpm
Copy link

docker ps gives a sensible output for ranges 1-5431/tcp, 5433-30000/tcp, 0.0.0.0:5432->5432/tcp but frustratingly docker-compose ps gives 1/tcp, 10/tcp, 100/tcp, 1000/tcp, 10000/tcp, 10001/tcp, 10002/tcp, 10003/tcp, 10004/tcp, 10005/tcp, 10006/tcp, 10007/tcp.

While large ranges like this are a bit nuts and that can be debated somewhere else, it would be helpful for docker-compose to match docker in the output format for ps in this case.

archibishop added a commit to archibishop/compose that referenced this issue Mar 3, 2020
Fixes docker#6910

Signed-off-by: Wagubi Brian <wagubib@gmail.com>
archibishop added a commit to archibishop/compose that referenced this issue Mar 3, 2020
Fixes docker#6910

Signed-off-by: Wagubi Brian <wagubib@gmail.com>
@stale
Copy link

stale bot commented Mar 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 21, 2020
@stale
Copy link

stale bot commented Sep 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@thaJeztah
Copy link
Member

.

@stale
Copy link

stale bot commented Sep 17, 2020

This issue has been automatically marked as not stale anymore due to the recent activity.

@stale stale bot removed the stale label Sep 17, 2020
@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 19, 2021
@thaJeztah
Copy link
Member

.

@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as not stale anymore due to the recent activity.

@stale stale bot removed the stale label Mar 19, 2021
@stale
Copy link

stale bot commented Sep 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 19, 2021
@thaJeztah
Copy link
Member

.

@stale
Copy link

stale bot commented Sep 20, 2021

This issue has been automatically marked as not stale anymore due to the recent activity.

@ndeloof
Copy link
Contributor

ndeloof commented Sep 20, 2021

Need to check how the docker/cli detect port range to display things this way and adopt the same approach (or even better: reuse code)

internaly tracked as https://docker.atlassian.net/browse/IL-595

@thaJeztah
Copy link
Member

For docker (container) ps, I think the formatting code is in https://github.com/docker/cli/blob/a32cd16160f1b41c1c4ae7bee4dac929d1484e59/cli/command/formatter/container.go#L297

I recall I also did docker/cli#581 for docker service ps. I think there was a reason for making that one (may have been covering additional corner-cases); we should probably combine the two though.

@ndeloof
Copy link
Contributor

ndeloof commented Sep 21, 2021

Seems we will need a 3rd copy/paste as Compose API doesn't rely on moby's types.Port but on compose API PortPublisher.

@ndeloof
Copy link
Contributor

ndeloof commented Sep 22, 2021

Ran a quick test trying to understand how port range are managed and detected by the Docker CLI, and...

$ docker run -p 8080-8090:80-90 -d nginx
d196e54b746554067c611e46ab99bf6ea0cd4e998f4f3e9560501d27e0c350f7
$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS        PORTS                                                                                                                                                                                                                                                         NAMES
d196e54b7465   nginx     "/docker-entrypoint.…"   8 seconds ago   Up 7 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp, 0.0.0.0:8081->81/tcp, :::8081->81/tcp, 0.0.0.0:8082->82/tcp, :::8082->82/tcp, 0.0.0.0:8083->83/tcp, :::8083->83/tcp, 0.0.0.0:8084->84/tcp, :::8084->84/tcp, 0.0.0.0:8085->85/tcp, :::8085->85/tcp, 0.0.0.0:8086->86/tcp, :::8086->86/tcp, 0.0.0.0:8087->87/tcp, :::8087->87/tcp, 0.0.0.0:8088->88/tcp, :::8088->88/tcp, 0.0.0.0:8089->89/tcp, :::8089->89/tcp, 0.0.0.0:8090->90/tcp, :::8090->90/tcp   goofy_bhaskara```

Did I missed something @thaJeztah ?

@thaJeztah
Copy link
Member

Hmm... yes, I see the same; looks like it's broken if both sides are not using the same port range.

If host and container range are the same, it groups correctly:

docker run -d -p 80-90:80-90 --name foobar nginx:alpine

docker ps

CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                           NAMES
34fdb2a76d0a   nginx:alpine   "/docker-entrypoint.…"   4 seconds ago   Up 2 seconds   0.0.0.0:80-90->80-90/tcp, :::80-90->80-90/tcp   foobar

docker rm -fv foobar

docker run -d \
  -p 60-61:60-61 \
  -p 62:61 \
  -p 80:80 \
  -p 81:80 \
  -p 90-95:90-95 \
  -p 90-92:90-92/udp \
  -p 93-96:93-96/udp \
  --name foobar \
  nginx:alpine

docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                                                                                                                                                                                                                  NAMES
ae58d6f2cea7   nginx:alpine   "/docker-entrypoint.…"   5 seconds ago    Up 4 seconds    0.0.0.0:60-61->60-61/tcp, :::60-61->60-61/tcp, 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:90-95->90-95/tcp, :::90-95->90-95/tcp, 0.0.0.0:90-96->90-96/udp, :::90-96->90-96/udp, 0.0.0.0:62->61/tcp, :::62->61/tcp, 0.0.0.0:81->80/tcp, :::81->80/tcp   foobar

docker rm -fv foobar

But if they're different, it breaks:

docker run -d -p 8080-8090:80-90 --name foobar nginx:alpine

CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                                                                                                                                                                                                                                                                                                                                                                                                                         NAMES
758a5fd0f373   nginx:alpine   "/docker-entrypoint.…"   4 seconds ago   Up 2 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp, 0.0.0.0:8081->81/tcp, :::8081->81/tcp, 0.0.0.0:8082->82/tcp, :::8082->82/tcp, 0.0.0.0:8083->83/tcp, :::8083->83/tcp, 0.0.0.0:8084->84/tcp, :::8084->84/tcp, 0.0.0.0:8085->85/tcp, :::8085->85/tcp, 0.0.0.0:8086->86/tcp, :::8086->86/tcp, 0.0.0.0:8087->87/tcp, :::8087->87/tcp, 0.0.0.0:8088->88/tcp, :::8088->88/tcp, 0.0.0.0:8089->89/tcp, :::8089->89/tcp, 0.0.0.0:8090->90/tcp, :::8090->90/tcp   foobar

docker rm -fv foobar

@thaJeztah
Copy link
Member

Looks like the implementation I did for services (in docker/cli#581) does seem to work, but admitted, swarm services don't allow binding to a specific IP-address, so that would need to be taken into account for docker ps as well;

docker service create -p 80-90:80-90 --name foobar nginx:alpine
docker service ls

ID             NAME      MODE         REPLICAS   IMAGE          PORTS
f9wt4oyuk6ts   foobar    replicated   1/1        nginx:alpine   *:80-90->80-90/tcp

docker service rm foobar

docker service create \
  -p 60-61:60-61 \
  -p 62:61 \
  -p 80:80 \
  -p 81:80 \
  -p 90-95:90-95 \
  -p 90-92:90-92/udp \
  -p 93-96:93-96/udp \
  --name foobar \
  nginx:alpine

docker service ls
ID             NAME      MODE         REPLICAS   IMAGE          PORTS
07m2ez999t8a   foobar    replicated   1/1        nginx:alpine   *:60-61->60-61/tcp, *:62->61/tcp, *:80-81->80/tcp, *:90-95->90-95/tcp, *:90-96->90-96/udp

docker service rm foobar

docker service create -p 8080-8090:80-90 --name foobar nginx:alpine

ID             NAME      MODE         REPLICAS   IMAGE          PORTS
cj3cp93xftu7   foobar    replicated   1/1        nginx:alpine   *:8080-8090->80-90/tcp

docker service rm foobar

@ndeloof ndeloof closed this as completed Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants