Why is 'sh: go: not found' appearing when installing Go in Alpine Docker image?

Mary-Kate Olsen
Release: 2024-11-12 18:44:01
Original
978 people have browsed it

Why is

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}"
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template