Home > Backend Development > Golang > Why is 'sh: go: not found' Encountered When Installing Go in Alpine Docker Images?

Why is 'sh: go: not found' Encountered When Installing Go in Alpine Docker Images?

Patricia Arquette
Release: 2024-11-12 21:46:02
Original
725 people have browsed it

Why is

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

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!

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