docker-library / golang

Docker Official Image packaging for golang
https://golang.org
BSD 3-Clause "New" or "Revised" License
1.45k stars 502 forks source link

`golang:1.22.0-bullseye` `linux/amd64` reports dpkg architecture `i386` #509

Closed tomyl closed 4 months ago

tomyl commented 4 months ago
$ docker run -it --rm --platform linux/amd64 golang:1.22.0-bullseye dpkg --print-architecture
i386

Same for golang:1.22.0-bookworm. This is different from the previous version I was using:

$ docker run -it --rm --platform linux/amd64 golang:1.21.5-bullseye dpkg --print-architecture
amd64

I discovered this because I install docker in one of my Dockerfiles and their repo doesn't seem to provide i386 packages.

xorkevin commented 4 months ago

Same issue here when running docker run --platform=linux/amd64 --rm -it --entrypoint /bin/sh golang:1.22.0-alpine3.19 and go env. I see:

...
GOARCH='386'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='386'
GOHOSTOS='linux'
...

Curiously enough, a docker inspect golang:1.22.0-alpine3.19 gives back

[
    {
        "Id": "sha256:6492fb3676d49badc7bc34c2485ade7e1afb195f12a878784ea62ad758e64252",
        "RepoTags": [
            "golang:1.22.0-alpine3.19"
        ],
        "RepoDigests": [
            "golang@sha256:298646364548cc5e1372e2612a6a2aaa53d44bed00284ecbc89b7aa8a83ad602"
        ],
...
        "Architecture": "386",
...

Seems like the bug could be on the docker side where only the x86 image is available and not x86_64?

A docker pull --platform=linux/amd64 golang:1.22.0-alpine3.19 as recommended by https://github.com/docker-library/golang/issues/481#issuecomment-1671707126 gives me back the following:

1.22.0-alpine3.19: Pulling from library/golang
Digest: sha256:298646364548cc5e1372e2612a6a2aaa53d44bed00284ecbc89b7aa8a83ad602
Status: Image is up to date for golang:1.22.0-alpine3.19
docker.io/library/golang:1.22.0-alpine3.19

which does seem to match the repo digest that reports 386 as the architecture.

And as another datapoint, I see that when pulling alpine:3.19 directly, I get the following:

$ docker run --platform=linux/amd64 --rm -it --entrypoint /bin/sh alpine:3.19             
Unable to find image 'alpine:3.19' locally
3.19: Pulling from library/alpine
4abcf2066143: Already exists 
Digest: sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b
Status: Downloaded newer image for alpine:3.19
/ # uname -m
x86_64
/ # apk --print-arch
x86_64

whereas apk --print-arch gives back x86 in golang:1.22.0-alpine3.19.

gunturaf commented 4 months ago

From hub.docker.com:

In 1.21-bullseye , there's linux/amd64 https://hub.docker.com/layers/library/golang/1.21-bullseye/images/sha256-47dff7622ed6f45236ba60c029d31165538351ec7d80a95b14b528dd77bc5b9d?context=explore

image

However, in 1.22-bullseye there's none. https://hub.docker.com/layers/library/golang/1.22-bullseye/images/sha256-3ec7caebf17aa0e2459ec6af24d7e555e6d32810ab16ef2b64140b7531ca1dfc?context=explore

image
tomyl commented 4 months ago

@xorkevin Thanks for pointing me to the https://github.com/docker-library/golang/issues/481#issuecomment-1671707126. I suppose this is simply a flawed/confusing docker behavior then, when the i386 image is available before amd64. Closing.

xorkevin commented 4 months ago

Thanks for reporting @tomyl , and thanks for confirming on the actual site @gunturaf . It hadn't occurred to me to look there. Seems like we're all looking for an x86_64 build that doesn't yet exist haha.

stvoidit commented 4 months ago

https://github.com/docker-library/golang/issues/511#issuecomment-1931959053

I ran into the same problem, so I added an architecture refinement to my Dockerfile. I think this may help to avoid a similar problem.

tomyl commented 4 months ago

The amd64 image is available now :smiley:

docker run -it --rm amd64/golang:1.22.0-bookworm dpkg --print-architecture
amd64

@stvoidit Thanks for the tip!