# SOLVED: Discrepancies in docker image sizes using the github.com/docker/docker/client package

**URL:** <https://forum.golangbridge.org/t/solved-discrepancies-in-docker-image-sizes-using-the-github-com-docker-docker-client-package/30114>\
**Category:** Code Review\
**Created:** [December 31, 2022, 5:56pm UTC](https://forum.golangbridge.org/t/solved-discrepancies-in-docker-image-sizes-using-the-github-com-docker-docker-client-package/30114 "2022-12-31T17:56:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfgratton](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/jfgratton/32/11930_2.png) [@jfgratton](https://forum.golangbridge.org/u/jfgratton)\
**Post date:** [December 31, 2022, 5:56pm UTC](https://forum.golangbridge.org/t/solved-discrepancies-in-docker-image-sizes-using-the-github-com-docker-docker-client-package/30114/1 "2022-12-31T17:56:34Z")

</div>

Hi, I’m building my own docker client in GO, but for some reason I get discrepancies when displaying/calculating an image size.

Using the standard docker client, I get:

```auto
[12:59:18|jfgratton@zenika:~]: docker images |egrep "certbui|postgres"
nexus:9820/postgresql14 latest-arm64 53e6d093a323 3 months ago 87.2MB
nexus:9820/certbuilder 2.02.00-arm64 6fb52fc0da42 3 months ago 226MB

```

While my tool gets this:

```auto
[12:49:25|jfgratton@zenika:~]: dtools lsi |egrep "certbui|postgres"
┃ nexus:9820 ┃ certbuilder ┃ 2.02.00-arm64 ┃ 6fb52fc0da42 ┃ 2022.09.03 15:50:41 ┃ 215MB ┃
┃ nexus:9820 ┃ postgresql14 ┃ latest-arm64 ┃ 53e6d093a323 ┃ 2022.09.08 18:07:51 ┃ 83MB ┃

```

The code I use from the docker/docker/client pkg is quite straightforward :

```auto
images, err := cli.ImageList(ctx, types.ImageListOptions{All: true})
	if err != nil {
		errmsg := fmt.Sprintf("%v", err)
		if errmsg == "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" {
			fmt.Println(errmsg)
			os.Exit(-1)
		} else {
			panic(err)
		}
	}

	for _, image := range images {
		//imgSpec := getImageTag(image.ID, image.RepoTags, image.Created, image.Size)
		imgspecSlice = append(imgspecSlice, getImageTag(image.ID, image.RepoTags, image.Created, image.Size)...)
	}

```

As per [types package - github.com/docker/docker/api/types - Go Packages](https://pkg.go.dev/github.com/docker/docker@v20.10.22+incompatible/api/types#ImageSummary) I’d expect the image size to be in the Size (int64) struct (side note: what use is VirtualSize for ?)

I understand that it’s not a Go question per-se, but more about Docker’s API…

–JFG

---

<div class="post-metadata">

**Author:** ![jfgratton](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/jfgratton/32/11930_2.png) [@jfgratton](https://forum.golangbridge.org/u/jfgratton)\
**Post date:** [January 1, 2023, 1:48pm UTC](https://forum.golangbridge.org/t/solved-discrepancies-in-docker-image-sizes-using-the-github-com-docker-docker-client-package/30114/2 "2023-01-01T13:48:11Z")

</div>

Fixed it… By the way, I’m a poor questioned, a code snippet was missing, where I compute the reported size to format it in MB.

Basically I was doing:

```auto
imgspec.size = (float32)(size / 1024.0 / 1024.0)
		imgspecSlice = append(imgspecSlice, imgspec)

```

Instead of :

```auto
imgspec.size = (float32)(size / 1000.0 / 1000.0)
		imgspecSlice = append(imgspecSlice, imgspec)

```

I was dividing the value by the “real” unit size (1024) instead of the human-readable size (1000).

SOLVED.
