cli
cli copied to clipboard
docs: Fix template error in cli example (#3727)
Fixes issue #3727
Template parsing error: template: :1:75: executing "" at <index $conf 0>: error calling index: index of untyped nil
Hmm... right, so I think the problem in your case was that you were using the example on a container that did not map any ports (i.e., no -p
or -P
options were set). In that case the template fails as it tries to iterate over an empty (or missing) slice.
For example;
docker run -d --name foo nginx:alpine
6757f08870ace82b937eecadda2e8d689cf1ea4eb263af65afa8add4576ad953
docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' foo
Template parsing error: template: :1:59: executing "" at <index $conf 0>: error calling index: index of untyped nil
Doing the same but with a container that does publish ports will show the expected output;
docker run -d --name foo2 -p 8080:80 -p 8081:443 nginx:alpine
5788ced50b6fb9ea726d6ffd36403fcb84a981e4ebc7950f9288bd3562fd7200
docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' foo2
443/tcp -> 8081 80/tcp -> 8080
I'm a bit confused about the addition of {{.Config.Image}}
in the template though 🤔
I'm a bit confused about the addition of
{{.Config.Image}}
in the template though
You are right, it's not working with {{.Config.Image}}
, I'm sorry, my fault.
Copy-pasted this from the wrong part of my bash script.
It should be like this:
$ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{with $conf}}{{(index . 0).HostPort}}{{else}}none{{end}} {{end}}' foo
3306/tcp -> none 33060/tcp -> none
In this case it will not throw an error in your first example and will give the same output as in your second example.
I'm going to fix my copy-pasting error in pr soon. Sorry about that. And thanks for your work!
Sorry for the delay; thank you! The change itself looks good, but some issues with the commit(s).
- Could you squash the two commits? (let me know if you need detailed instructions)
- It appears your commit message is missing a DCO sign-off, causing the DCO check to fail.
We require all commit messages to have a Signed-off-by
line with your name
and e-mail (see "Sign your work"
in the CONTRIBUTING.md in this repository), which looks something like:
Signed-off-by: YourFirsName YourLastName <[email protected]>
There is no need to open a new pull request, but to fix this (and make CI pass), you need to amend the commit(s) in this pull request, and "force push" the amended commit.
Unfortunately, it's not possible to do so through GitHub's web UI, so this needs to be done through the git commandline.
You can find some instructions in the output of the DCO check (which can be found in the "checks" tab on this pull request), as well as in the Moby contributing guide.
Steps to do so "roughly" come down to:
-
Set your name and e-mail in git's configuration:
git config --global user.name "YourFirstName YourLastName" git config --global user.email "[email protected]"
(Make sure to use your real name (not your GitHub username/handle) and e-mail)
-
Clone your fork locally
-
Check out the branch associated with this pull request
-
Sign-off and amend the existing commit(s)
git commit --amend --no-edit --signoff
If your pull request contains multiple commits, either squash the commits (if needed) or sign-off each individual commit.
-
Force push your branch to GitHub (using the
--force
or--force-with-lease
flags) to update the pull request.
Sorry for the hassle (I wish GitHub would make this a bit easier to do), and let me know if you need help or more detailed instructions!
I'm sorry for the delay..
I squashed and signed off my commit. Hope that it's ok now.
Thanks!