Home >Backend Development >Golang >How to Install Go in Alpine Linux Docker Images?
Installing Go in Alpine Linux Docker Images
To install Go in an Alpine Docker image, the following steps can be taken:
Set the PATH environment variable to include the Go binary directory, as shown below:
export PATH=$PATH:/usr/local/go/bin
However, if the command go version returns "sh: go: not found," this indicates that some components may be missing.
To overcome this issue, you can consider using a multi-stage build approach. In this method, you can start with a Go base image, such as golang:1.13-alpine, and then copy the necessary files and directories from that image into your Alpine image. Here's an example:
FROM XXX COPY --from=golang:1.13-alpine /usr/local/go/ /usr/local/go/ ENV PATH="/usr/local/go/bin:${PATH}"
By using this multi-stage build, you can ensure that your Alpine image includes all the required Go components and can be used to run Go programs effectively.
The above is the detailed content of How to Install Go in Alpine Linux Docker Images?. For more information, please follow other related articles on the PHP Chinese website!