gocv
gocv copied to clipboard
question: build Dockerfile with multi-stage
I'm trying to build multi-stage Dockerfile so I can reduce the image size from current size (2GB).
I'm using gocv/opencv:4.5.2
to build the binary file on first stage and debian:buster
for the second stage (I saw that you use buster for the gocv image, so I'm using it also).
I'm copying /usr/local into the second-stage image, since this is what configured in the cmake prefix configuration.
When I'm running the docker image I get an error that dependent files are missing... I can find them but then it keeps happening over and over with different files...
Has anyone managed to use multi-stage approach here?
I have the same question. Did you end up finding a solution?
I have the same question. Did you end up finding a solution?
Nope.. I'm still using one step instead.
Can I ask, your OpencV made arm dockerfile ?
This is my current Dockerfile:
FROM gocv/opencv:4.5.2 AS build-stage
WORKDIR $GOPATH/src/github.com/Anzu-Team/anzu_go
COPY go.mod go.sum ./
RUN go env -w GO111MODULE=on
RUN go mod download
RUN go mod verify
COPY . .
RUN GOOS=linux GOARCH=amd64 go build -a -ldflags='-w -s' -tags matprofile -o /go/bin/anzu_go/anzu_image_processor/anzu_image_processor ./anzu_image_processor/main.go
This dockerfile only supports AMD64 and not ARM64.
This is my test dockerfile
FROM --platform=$BUILDPLATFORM gocv/opencv:4.5.3 as builder
ENV TZ=Asia/Shanghai LANG="C.UTF-8"
ARG TARGETARCH
ARG TARGETOS
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.io,direct
# Copy the go source
COPY video video
# Build
RUN CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -o videod video/cmd/main.go
FROM gocv/opencv:4.5.3
WORKDIR /
COPY --from=builder /workspace/videod .
COPY --from=builder /workspace/video/net /etc/
ENTRYPOINT ["/videod"]
This is my current Dockerfile:
FROM gocv/opencv:4.5.2 AS build-stage WORKDIR $GOPATH/src/github.com/Anzu-Team/anzu_go COPY go.mod go.sum ./ RUN go env -w GO111MODULE=on RUN go mod download RUN go mod verify COPY . . RUN GOOS=linux GOARCH=amd64 go build -a -ldflags='-w -s' -tags matprofile -o /go/bin/anzu_go/anzu_image_processor/anzu_image_processor ./anzu_image_processor/main.go
This only supports THE AMD64 architecture and does not support the ARM64 architecture ...