I tried the following Dockerfile that does just build.
FROM golang:1.23 as builder
ENV CGO_ENABLED=1
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN go build -o server ./cmd/wine
FROM gcr.io/distroless/static-debian12
COPY --from=builder /app/server /
CMD ["/server"]
I got the following error. It looks like SQLite amalgamation from mattn/go-sqlite doesn't work for the extension.
Step #0: Step 8/11 : RUN go build -o server ./cmd/wine
Step #0: ---> Running in 154b0c8309b1
Step #0: # github.com/asg017/sqlite-vec-go-bindings/cgo
Step #0: In file included from /go/pkg/mod/github.com/asg017/sqlite-vec-go-bindings@v0.1.1/cgo/lib.go:4:
Step #0: ./sqlite-vec.h:4:10: fatal error: sqlite3ext.h: No such file or directory
Step #0: 4 | #include "sqlite3ext.h"
Step #0: | ^~~~~~~~~~~~~~
Step #0: compilation terminated.
Thus, I tried to go around the amalgamation and use the system-wide SQLite3 library for compiling and linking as follows:
FROM golang:1.23 as builder
ENV CGO_ENABLED=1
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
build-essential \
libsqlite3-dev
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
# RUN go get github.com/mattn/go-sqlite3
# RUN go get github.com/asg017/sqlite-vec-go-bindings/cgo
COPY . .
ARG CMD
RUN go build -tags libsqlite3 -o server ./cmd/${CMD}
FROM gcr.io/distroless/static-debian12
COPY --from=builder /app/server /
COPY --from=builder /app/vectors.db /
CMD ["/server"]
This also fails with the following errors.
Step #0: Step 9/13 : RUN go build -tags libsqlite3 -o server ./cmd/${CMD}
Step #0: ---> Running in 8cc4e1de811b
Step #0: # github.com/foobar/foobar
Step #0: /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
Step #0: /usr/bin/gcc -m64 -o $WORK/b001/exe/a.out -Wl,--export-dynamic-symbol=_cgo_panic -Wl,--export-dynamic-symbol=_cgo_topofstack -Wl,--export-dynamic-symbol=authorizerTrampoline -Wl,--export-dynamic-symbol=callbackTrampoline -Wl,--export-dynamic-symbol=commitHookTrampoline -Wl,--export-dynamic-symbol=compareTrampoline -Wl,--export-dynamic-symbol=crosscall2 -Wl,--export-dynamic-symbol=doneTrampoline -Wl,--export-dynamic-symbol=preUpdateHookTrampoline -Wl,--export-dynamic-symbol=rollbackHookTrampoline -Wl,--export-dynamic-symbol=stepTrampoline -Wl,--export-dynamic-symbol=updateHookTrampoline -Wl,--compress-debug-sections=zlib /tmp/go-link-1907433757/go.o /tmp/go-link-1907433757/000000.o /tmp/go-link-1907433757/000001.o /tmp/go-link-1907433757/000002.o /tmp/go-link-1907433757/000003.o /tmp/go-link-1907433757/000004.o /tmp/go-link-1907433757/000005.o /tmp/go-link-1907433757/000006.o /tmp/go-link-1907433757/000007.o /tmp/go-link-1907433757/000008.o /tmp/go-link-1907433757/000009.o /tmp/go-link-1907433757/000010.o /tmp/go-link-1907433757/000011.o /tmp/go-link-1907433757/000012.o /tmp/go-link-1907433757/000013.o /tmp/go-link-1907433757/000014.o /tmp/go-link-1907433757/000015.o /tmp/go-link-1907433757/000016.o /tmp/go-link-1907433757/000017.o /tmp/go-link-1907433757/000018.o /tmp/go-link-1907433757/000019.o /tmp/go-link-1907433757/000020.o /tmp/go-link-1907433757/000021.o /tmp/go-link-1907433757/000022.o /tmp/go-link-1907433757/000023.o /tmp/go-link-1907433757/000024.o /tmp/go-link-1907433757/000025.o /tmp/go-link-1907433757/000026.o /tmp/go-link-1907433757/000027.o /tmp/go-link-1907433757/000028.o /tmp/go-link-1907433757/000029.o /tmp/go-link-1907433757/000030.o /tmp/go-link-1907433757/000031.o /tmp/go-link-1907433757/000032.o /tmp/go-link-1907433757/000033.o /tmp/go-link-1907433757/000034.o /tmp/go-link-1907433757/000035.o /tmp/go-link-1907433757/000036.o /tmp/go-link-1907433757/000037.o /tmp/go-link-1907433757/000038.o /tmp/go-link-1907433757/000039.o -O2 -g -O2 -g -lsqlite3 -ldl -O2 -g -lresolv -O2 -g -lpthread -O2 -g -no-pie
Step #0: /usr/bin/ld: /tmp/go-link-1907433757/000002.o: undefined reference to symbol 'sqrtf@@GLIBC_2.2.5'
Step #0: /usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
Step #0: collect2: error: ld returned 1 exit status
Step #0:
Step #0: The command '/bin/sh -c go build -tags libsqlite3 -o server ./cmd/${CMD}' returned a non-zero code: 1
Could you please advise or provide a simple Dockerfile example? Thanks!
Hi Alex,
I'd like to build a Docker image for our Go server that uses https://github.com/mattn/go-sqlite3 and https://github.com/asg017/sqlite-vec. I'm having a hard time building a static or dynamically linked binary with CGO.
I tried the following Dockerfile that does just build.
I got the following error. It looks like SQLite amalgamation from mattn/go-sqlite doesn't work for the extension.
Thus, I tried to go around the amalgamation and use the system-wide SQLite3 library for compiling and linking as follows:
This also fails with the following errors.
Could you please advise or provide a simple Dockerfile example? Thanks!