Repository: moby/moby (language: go)

Issue:
c8d: docker history requires "canonical" name (errors on dangling references)
### Description

When running `docker history` on a dangling image, I get an error instead of the history. :smile:

### Reproduce

```console
$ docker images | grep 002073b9a94e
<none>       <none>    002073b9a94e   11 minutes ago   21MB
$ docker history 002073b9a94e
Error response from daemon: repository name must be canonical
```

### Expected behavior

The "Docker" (`docker history`) representation of this: :joy:

```console
$ ctr content get sha256:002073b9a94eb5772809625c00075c6d454fceae35ccfd7231acdce8b8f3b572 | jq '.config.digest' -r | xargs ctr content get | jq '.history'
[
  {
    "created": "2023-03-29T18:19:24.348438709Z",
    "created_by": "/bin/sh -c #(nop) ADD file:9a4f77dfaba7fd2aa78186e4ef0e7486ad55101cefc1fabbc1b385601bb38920 in / "
  },
  {
    "created": "2023-03-29T18:19:24.45578926Z",
    "created_by": "/bin/sh -c #(nop)  CMD [\"/bin/sh\"]",
    "empty_layer": true
  },
...
```

### docker version

```bash
Client:
 Version:           
 API version:       1.43 (downgraded from 1.44)
 Go version:        go1.19.9
 Git commit:        25dd1ecc755f7f351a123faf4feca57e2cf726ca
 Built:             Tue May  9 21:27:30 2023
 OS/Arch:           linux/amd64
 Context:           default

Server:
 Engine:
  Version:          dev
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.19.9
  Git commit:       1d545a66ef034fbe798340a77eb08413345a1b42
  Built:            Tue May  9 21:30:32 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.7.0
  GitCommit:        1fbd70374134b891f97ce19c70b6e50c7b9f4e0d
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061b
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
```


### docker info

```bash
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 7
 Server Version: dev
 Storage Driver: overlayfs
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1fbd70374134b891f97ce19c70b6e50c7b9f4e0d
 runc version: v1.1.7-0-g860f061b
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.10.0-21-amd64
 Operating System: Alpine Linux v3.17
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 62.44GiB
 Name: a8f528f3ee35
 ID: 6df0a9b7-d5cb-405c-aad7-170d9dba2b5f
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
```


### Additional Info

_No response_


Discussion / hints:
Ooohh, I'll TAL :)

Fix patch:
diff --git a/daemon/containerd/image_history.go b/daemon/containerd/image_history.go
index a99716ead73be..a2d0c11425b4c 100644
--- a/daemon/containerd/image_history.go
+++ b/daemon/containerd/image_history.go
@@ -90,13 +90,16 @@ func (i *ImageService) ImageHistory(ctx context.Context, name string) ([]*imaget
 			return nil, err
 		}
 
-		tags := make([]string, len(tagged))
-		for i, t := range tagged {
+		var tags []string
+		for _, t := range tagged {
+			if isDanglingImage(t) {
+				continue
+			}
 			name, err := reference.ParseNamed(t.Name)
 			if err != nil {
 				return nil, err
 			}
-			tags[i] = reference.FamiliarString(name)
+			tags = append(tags, reference.FamiliarString(name))
 		}
 		history[0].Tags = tags
 	}


Test patch: