亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CGO_Enabled=1 需要在 Alpine Docker 容器中使用 SQLite 構建 Go

CGO_Enabled=1 需要在 Alpine Docker 容器中使用 SQLite 構建 Go

Go
HUH函數 2022-09-05 10:04:29
我正在嘗試編譯一個Alpine Go容器,該容器使用GORM,它是內存中數據庫的SQLite驅動程序。這取決于是否啟用了 CGO。我的二進制文件使用 構建和執行正常,但是當運行我的 docker 映像(后跟 )時,我收到錯誤消息:go build .docker build .docker run $imagenamestandard_init_linux.go:219: exec user process caused: no such file or directory我正在Windows 10 64位上構建。我已經安裝了gcc。兩者都在我的$env:路徑中。我已將包中所有文件的行尾更改為Linux樣式(LF)。C:\TDM-GCC-64\binC:\cygwin64\bin我的 docker 文件如下:FROM golang:1.16.4-alpine AS builderRUN apk update \    && apk add --no-cache git \    && apk add --no-cache ca-certificates \    && apk add --update gcc musl-dev \    && update-ca-certificates# Create a user so that the image doens't run as rootRUN adduser \    --disabled-password \    --gecos "" \    --home "/nonexistent" \    --shell "/sbin/nologin" \    --no-create-home \    --uid "100001" \    "appuser"# Set the working directory inside the container.WORKDIR $GOPATH/src/app# Copy all files from the current directory to the working directoryCOPY . .# Fetch dependencies.RUN go get -u -d -v# Go build the binary, specifying the final OS and architecture we're looking forRUN GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/app -tags timetzdataFROM scratch# Import the user and group files from the builder.COPY --from=builder /etc/passwd /etc/passwdCOPY --from=builder /etc/group /etc/groupCOPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/# Copy our static executable.COPY --from=builder /go/bin/app/go/bin/app# Use the user that we've just created, one that isn't rootUSER appuser:appuserENTRYPOINT ["/go/bin/app"]你能幫我理解為什么我的 docker 鏡像無法運行嗎?如果它有任何價值,則打開數據庫的Go代碼行就是這樣。由于這適用于使用本地構建或使用Go構建,因此我認為這無關緊要。go run .db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
查看完整描述

2 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

Libc 不存在于零頭。我把它改成了alpine,它解決了這個錯誤。


查看完整回答
反對 回復 2022-09-05
?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

解決方案是在Dockerfile中使用apk安裝gcc和alpine-sdk軟件包。在上面的問題中只安裝了 gcc。


查看完整回答
反對 回復 2022-09-05
  • 2 回答
  • 0 關注
  • 359 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號