duanmei1930 2018-01-08 04:12
浏览 352
已采纳

是否可以通过docker golang:alpine image构建静态的sqlite Go应用程序?

I'm trying to build my app which contains go-sqlite3 by docker.

main.go

package main

import (
        "database/sql"

        _ "github.com/mattn/go-sqlite3"
)

func main() {
        sql.Open("sqlite3", "test.db")
}

Dockerfile

FROM golang:alpine
RUN apk add --no-cache git
RUN apk add --no-cache sqlite-libs sqlite-dev
RUN apk add --no-cache build-base
WORKDIR /go/src/app
COPY *.go ./
RUN go-wrapper download
RUN go-wrapper install

I use this command to copy the compiled program out to my host OS (Arch Linux).

docker build -t mygo .
docker run --rm -v $$PWD:/usr/src/app mygo /bin/cp /go/bin/app /usr/src/app

The problem is the compiled program is missing dynamic library

$  ldd app
   ...
   libc.musl-x86_64.so.1 => not found

What I expected is like

$  ldd app
not a dynamic executable
  • 写回答

2条回答 默认 最新

  • doujie4050 2018-01-08 06:16
    关注

    refer to how to create a statically linked golang executable with go 1.5+

    Change the Dockerfile's go-wrapper install line into

    RUN go-wrapper install -ldflags "-linkmode external -extldflags -static"   
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥100 华为ens111111111111111111111111111111111111111111
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题