docker build fail undefined: sqlite3.Error
ericnts opened this issue · 2 comments
when run docker build -t test:v2 .
out:
`
[+] Building 3.6s (13/18) docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 771B 0.0s
=> [internal] load metadata for docker.io/library/golang:alpine 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [builder 1/9] FROM docker.io/library/golang:alpine 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 1.02kB 0.0s
=> CACHED [builder 2/9] RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories 0.0s
=> CACHED [builder 3/9] RUN apk update --no-cache && apk add --no-cache tzdata 0.0s
=> CACHED [builder 4/9] WORKDIR /build 0.0s
=> CACHED [builder 5/9] ADD go.mod . 0.0s
=> CACHED [builder 6/9] ADD go.sum . 0.0s
=> [builder 7/9] RUN go mod download 1.8s
=> [builder 8/9] COPY . . 0.0s
=> ERROR [builder 9/9] RUN go build -ldflags="-s -w" -o /app/main main.go 1.8s
[builder 9/9] RUN go build -ldflags="-s -w" -o /app/main main.go:
1.751 # command-line-arguments
1.751 ./main.go:10:30: undefined: sqlite3.Error
Dockerfile:18
16 | COPY . .
17 |
18 | >>> RUN go build -ldflags="-s -w" -o /app/main main.go
19 |
20 | FROM scratch
ERROR: failed to solve: process "/bin/sh -c go build -ldflags="-s -w" -o /app/main main.go" did not complete successfully: exit code: 1`
Dockerfile:
`FROM golang:alpine AS builder
LABEL stage=gobuilder
ENV CGO_ENABLED 0
ENV GOPROXY https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache tzdata
WORKDIR /build
ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
RUN go build -ldflags="-s -w" -o /app/main main.go
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
ENV TZ Asia/Shanghai
WORKDIR /app
COPY --from=builder /app/chassis /app/chassis
COPY --from=builder /app/etc /app/etc
CMD ["./chassis", "-f", "etc/chassis-api.yaml"]`
Src:
main.go:
`package main
import (
"errors"
"github.com/mattn/go-sqlite3"
)
func main() {
var err error
if sqliteErr := new(sqlite3.Error); errors.As(err, sqliteErr) {
println("ass")
}
println("ress")
}
`
go-sqlite3 is cgo module. you need to install C compiler.
It‘s work, thinks