dsiimyoc804955 2018-08-28 11:06 采纳率: 100%
浏览 1858
已采纳

如何在Alpine Linux中安装Go

I am trying to install Go inside an Alpine Docker image. For that I downloaded tar file from here inside my alpine docker image, untar it using following command:

tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

exported PATH to have go binary as:

export PATH=$PATH:/usr/local/go/bin

However, when I say go version then it says that sh: go: not found. I am quite new to alpine. Does anyone know, what I am missing here?

Steps to reproduce-

$ docker run -it alpine sh
$ wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin
$ go version
  • 写回答

4条回答 默认 最新

  • dongyongyin5339 2018-08-28 12:05
    关注

    With Alpine, you have libmusl instead of glibc. Alpine's libmusl is not a 1 for 1 replacement. Code linked against glibc will show a not found error which is actually from the dynamic linker. You can see what libraries are linked to the binary with ldd:

    / # ldd /usr/local/go/bin/go
            /lib64/ld-linux-x86-64.so.2 (0x7f63ceed1000)
            libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f63ceed1000)
            libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f63ceed1000)
    

    There are two options. The preferred option, and one used by docker's go images on Alpine, is to compile the go binaries on Alpine. You can see this in the Dockerfile for the golang image: https://github.com/docker-library/golang/blob/69f2d2a132565bf60afc91813801a3bdcc981526/1.10/alpine3.8/Dockerfile

    The other option is to install glibc on Alpine, but once you start doing things like that, I'd question why use Alpine at all, and whether Debian or CentOS would be a more appropriate base image for you. Alpine has a wiki topic on this and there are third parties that have created glibc packages for alpine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?