Skip to content

docs: Fix template error in cli example (#3727)#3728

Merged
vvoland merged 1 commit into
docker:masterfrom
maxmorozoff:issue-3727
May 14, 2026
Merged

docs: Fix template error in cli example (#3727)#3728
vvoland merged 1 commit into
docker:masterfrom
maxmorozoff:issue-3727

Conversation

@maxmorozoff
Copy link
Copy Markdown
Contributor

Fixes issue #3727

Template parsing error: template: :1:75: executing "" at <index $conf 0>: error calling index: index of untyped nil

@maxmorozoff maxmorozoff requested a review from thaJeztah as a code owner August 3, 2022 20:30
@thaJeztah
Copy link
Copy Markdown
Member

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 🤔

@maxmorozoff
Copy link
Copy Markdown
Contributor Author

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!

@thaJeztah
Copy link
Copy Markdown
Member

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 <yourname@example.org>

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:

  1. Set your name and e-mail in git's configuration:

    git config --global user.name "YourFirstName YourLastName"
    git config --global user.email "yourname@example.org"

    (Make sure to use your real name (not your GitHub username/handle) and e-mail)

  2. Clone your fork locally

  3. Check out the branch associated with this pull request

  4. 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.

  5. 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!

@maxmorozoff
Copy link
Copy Markdown
Contributor Author

I'm sorry for the delay..

I squashed and signed off my commit.
Hope that it's ok now.

Thanks!

@thaJeztah thaJeztah requested a review from a team as a code owner May 14, 2026 00:04
@thaJeztah thaJeztah removed the dco/no label May 14, 2026
@thaJeztah thaJeztah added this to the 29.5.0 milestone May 14, 2026
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah requested a review from vvoland May 14, 2026 00:06
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: Max Morozov <max@morozov.page>
Signed-off-by: Max Morozov <gtmax.yo@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@vvoland vvoland merged commit 33b3258 into docker:master May 14, 2026
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants