Installed Go binary not found in path on Alpine Linux Docker

前端 未结 6 952
Happy的楠姐
Happy的楠姐 2020-12-22 17:54

I\'ve got a Go binary I\'m trying to run on the Alpine Docker image.

This works fine for the Docker Go binary.

docker run -it alpine:3.3 sh
apk add -         


        
相关标签:
6条回答
  • 2020-12-22 18:34
    RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
    

    Since the musl and glibc so are compatible, you can make this symlink and it will fix the missing dependency.

    0 讨论(0)
  • 2020-12-22 18:41

    I compiled go binary in alpine with these options

    GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o [name of binary]
    

    It worked.

    0 讨论(0)
  • 2020-12-22 18:46

    When building under Debian 9 (Stretch) / Go 1.10.2 and running under Alpine 3.7.0:

    CGO_ENABLED=0 go build
    

    Neither GOOS=linux nor GOARCH=amd6 was necessary.

    0 讨论(0)
  • 2020-12-22 18:50

    Alternatively, you can (meanwhile) use the golang:alpine image from Docker Hub to compile and run your code.

    docker run -v ${YOUR_CODE_PATH}:/go/src/example -it golang:alpine sh
    cd src/example
    go build .
    ldd example
        /lib/ld-musl-x86_64.so.1 (0x7f677fcf7000)
        libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f677fcf7000)
    
    0 讨论(0)
  • 2020-12-22 18:51

    You can install libc6-compat

    RUN apk add --no-cache libc6-compat
    
    0 讨论(0)
  • 2020-12-22 18:53

    Depending on the nature of the program, you might want to compile your go program with static link options, such as the following:

    -x -a -tags netgo -installsuffix netgo

    Afterwards you do not need to worry about linking the correct libraries.

    0 讨论(0)
提交回复
热议问题