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

Specifying GOTOOLCHAIN in golang:alpine fails #487

Closed chradcliffe closed 10 months ago

chradcliffe commented 10 months ago

The go command in golang:alpine doesn't seem to be able to find the path to the Go toolchain downloaded when specifying GOTOOLCHAIN:

❯ docker run --rm -it golang:alpine
Unable to find image 'golang:alpine' locally
alpine: Pulling from library/golang
Digest: sha256:445f34008a77b0b98bf1821bf7ef5e37bb63cc42d22ee7c21cc17041070d134f
Status: Downloaded newer image for golang:alpine
/go # GOTOOLCHAIN=go1.20.7 go version
go: downloading go1.20.7 (linux/amd64)
go: exec go1.20.7: no such file or directory
/go #

The same command works just fine in golang:latest:

❯ docker run --rm -it golang
Unable to find image 'golang:latest' locally
latest: Pulling from library/golang
de4cac68b616: Pull complete
d31b0195ec5f: Pull complete
9b1fd34c30b7: Pull complete
2f744fb50e06: Pull complete
661ee9827c7b: Pull complete
fa5c1764d694: Pull complete
Digest: sha256:b490ae1f0ece153648dd3c5d25be59a63f966b5f9e1311245c947de4506981aa
Status: Downloaded newer image for golang:latest
root@e76b63273844:/go# GOTOOLCHAIN=go1.20.7 go version
go: downloading go1.20.7 (linux/amd64)
go version go1.20.7 linux/amd64
root@e76b63273844:/go#

Is there something different about the PATH variable in golang:alpine that is causing issues here maybe?

yosifkit commented 10 months ago

I think this is related to the fact that only go 1.21+ has binaries that work correctly on Alpine. (https://github.com/docker-library/golang/pull/474).

chradcliffe commented 10 months ago

So if I understand correctly:

Is that correct?

yosifkit commented 10 months ago

That is correct; the upstream binary releases of 1.20.x don't work on Alpine.

chradcliffe commented 10 months ago

That makes sense. Thank you for the clarification.