cli icon indicating copy to clipboard operation
cli copied to clipboard

docker service inspect --pretty should show secrets/configs

Open thaJeztah opened this issue 7 years ago • 12 comments

Create a service using a secret and a config:

echo "bla" | docker config create foo.conf -
echo "bla" | docker secret create secret.conf -


docker service create -d \
    --config source=foo.conf,target=/foo.conf,uid=123,gid=456 \
    --secret source=secret.conf,target=/secret.conf,uid=234,gid=567 \
    --replicas 1 \
    --name myservice \
    nginx:alpine

Inspect the service with the --pretty option:

docker service inspect myservice --pretty   

ID:		ib7yble4rm5qbz3ijmk83cxeh
Name:		myservice
Service Mode:	Replicated
 Replicas:	1
Placement:
UpdateConfig:
 Parallelism:	1
 On failure:	pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Update order:      stop-first
RollbackConfig:
 Parallelism:	1
 On failure:	pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Rollback order:    stop-first
ContainerSpec:
 Image:		nginx:alpine@sha256:48947591194ac5a9dce1e110f9198a547debb21630f121081640b87d99ca8b11
Resources:
Endpoint Mode:	vip

Notice that no information about the configs or secrets is printed.

Inspect the service without --pretty:

docker service inspect myservice
[
    {
        "ID": "ib7yble4rm5qbz3ijmk83cxeh",
        "Version": {
            "Index": 776
        },
        "CreatedAt": "2018-02-28T09:42:57.612406537Z",
        "UpdatedAt": "2018-02-28T09:42:57.612406537Z",
        "Spec": {
            "Name": "myservice",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "nginx:alpine@sha256:48947591194ac5a9dce1e110f9198a547debb21630f121081640b87d99ca8b11",
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {},
                    "Secrets": [
                        {
                            "File": {
                                "Name": "/secret.conf",
                                "UID": "234",
                                "GID": "567",
                                "Mode": 292
                            },
                            "SecretID": "yv9vtn86nugxsbshu1ccumlod",
                            "SecretName": "secret.conf"
                        }
                    ],
                    "Configs": [
                        {
                            "File": {
                                "Name": "/foo.conf",
                                "UID": "123",
                                "GID": "456",
                                "Mode": 292
                            },
                            "ConfigID": "j915gbt419wv9022nr2w8pqdh",
                            "ConfigName": "foo.conf"
                        }
                    ],
                    "Isolation": "default"
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "arm64",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "386",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "ppc64le",
                            "OS": "linux"
                        },
                        {
                            "Architecture": "s390x",
                            "OS": "linux"
                        }
                    ]
                },
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "vip"
            }
        },
        "Endpoint": {
            "Spec": {}
        }
    }
]

Notice that information about secrets and configs is present, so this would be an easy change (just adjusting the template for --pretty)

thaJeztah avatar Feb 28 '18 09:02 thaJeztah

Hi I have taken a look into this bug and I noticed the pretty template can be found here: https://github.com/docker/cli/blob/c0ffb9491cdffb628e18bb491b566255987fd28d/cli/command/formatter/service.go#L19-L129

I traced the Raw template to the https://github.com/docker/cli/blob/c0ffb9491cdffb628e18bb491b566255987fd28d/cli/command/formatter/formatter.go#L64 file and I believe the logic is stored within one of the functions within the parseFormat() function.

Is my assumption accurate? If not where do you suggest looking?

Vimal-Raghubir avatar Mar 20 '18 01:03 Vimal-Raghubir

Yes, I think that sounds about right; if you’re interested to work on this, that’d be great!

thaJeztah avatar Mar 20 '18 20:03 thaJeztah

I am definitely interested in working on this and thank you for the reassurance. I am fairly new to contributing to Docker and was wondering how should i go about testing the inspect command changes I would make. Do I need to clone the repository and debug in visual studio code? Or do I need to run some scripts such as the ones in the MakeFile?

Vimal-Raghubir avatar Mar 20 '18 20:03 Vimal-Raghubir

The easiest way to build is to use the docker.Makefile; that will build the source in a container (but bind-mounts the source, so that you can edit using your preferred editor), for example;

make -f docker.Makefile binary shell

Will build the CLI from source and starts an interactive container in which you can try the binary you built

thaJeztah avatar Mar 20 '18 20:03 thaJeztah

Thank you so much for the advice.

Vimal-Raghubir avatar Mar 20 '18 21:03 Vimal-Raghubir

@thaJeztah the issue was not close and I can't see a pr for it, should I assume I can work on it?

essamhassan avatar Apr 15 '18 03:04 essamhassan

shouldn't this issue be closed?

Asalle avatar Oct 05 '19 16:10 Asalle

is there any update regarding to this issue ? @thaJeztah Seems something merged which points this issue.

mrtrkmn avatar May 09 '20 21:05 mrtrkmn

Thank you so much for the advice.

HI, I made a change to this code and also have a suggestion too. kindly go through my changes, don't mind the way I type. Thanks. @thaJeztah

adeniyistephen avatar Nov 02 '20 16:11 adeniyistephen

Guess the Issue can be closed, right?

Running docker service inspect _service_ --pretty show the desired informations on the latest Version 20.10.7

PatrickLaabs avatar Aug 06 '21 08:08 PatrickLaabs

I come from https://github.com/MunGell/awesome-for-beginners#go and find this issue. I think this can be closed so no more people come to this and realize this is an issue they can tackle but it's already solved.

yusufmalikul avatar Aug 10 '21 02:08 yusufmalikul

Running docker service inspect _service_ --pretty and it's showing desired information on Version 20.10. 16 as well now. Can we close this?

DanielPickens avatar May 25 '22 02:05 DanielPickens