Installing Go in Alpine Linux
When attempting to install Go in an Alpine Docker image, users may encounter the error "sh: go: not found" when checking the version after extracting the tar file and modifying the PATH.
Solution:
The issue arises because the Go binaries are not copied into the image during the installation process. To resolve this, consider using multi-stage builds, as demonstrated below:
FROM XXX COPY --from=golang:1.13-alpine /usr/local/go/ /usr/local/go/ ENV PATH="/usr/local/go/bin:${PATH}"
In this multi-stage build, the first stage is the official Golang image, from which the Go installation is copied using COPY --from. The second stage adds the Go binaries to the PATH environment variable.
The above is the detailed content of Why is 'sh: go: not found' Encountered When Installing Go in Alpine Docker Images?. For more information, please follow other related articles on the PHP Chinese website!