Home >Backend Development >Golang >How to Install Go in Alpine Linux Docker Images?

How to Install Go in Alpine Linux Docker Images?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-12 10:06:021093browse

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:

  • Download the Go tar file from the official Go website.
  • Extract the tar file using the command tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz.
  • 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!

Statement:
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