Installing Go in Alpine Linux Docker Image
When attempting to install Go inside an Alpine Docker image, an error message indicating "sh: go: not found" may appear after extracting the Go tar file, adding "/usr/local/go/bin" to PATH, and attempting to run "go version."
To resolve this issue, consider utilizing multi-stage builds in your Dockerfile:
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 Dockerfile, the first stage pulls the golang:1.13-alpine image. Then, the second stage uses COPY to copy the /usr/local/go/ directory from the golang image to the destination image. Finally, the PATH environment variable is set to include the Go binary directory.
With this approach, Go is successfully installed in the Docker image, and you can proceed with using Go commands without encountering the "sh: go: not found" error.
The above is the detailed content of Why is 'sh: go: not found' appearing when installing Go in Alpine Docker image?. For more information, please follow other related articles on the PHP Chinese website!