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

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

如何在支持 golang 的 gRPC 中減小 docker 鏡像的大???

我有一些使用 gRPC/golang 進行通信的服務器和客戶端?,F在我想將我的應用程序容器化,但是包含 goland 執行和 grpc 支持的 docker 鏡像的大小更大(超過 1GB)。我想減小 docker 圖像的大小。所需的 golang 版本為 1.9 及更高版本。這是給出的 Dockerfile 腳本。如果有其他方法請建議。FROM golang:1.11RUN apt-get update && \    apt-get -y install git unzip build-essential autoconf libtoolRUN git clone https://github.com/google/protobuf.git && \    cd protobuf && \    ./autogen.sh && \    ./configure && \    make && \    make install && \    ldconfig && \    make clean && \    cd .. && \    rm -r protobufRUN go get google.golang.org/grpcRUN go get github.com/golang/protobuf/protoc-gen-goRUN ls -laWORKDIR /helloworldCOPY . /helloworldRUN protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworldCMD ["go", "run", "helloworld/greeter_server/main.go"]
查看完整描述

2 回答

?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

嘗試制作這樣的多級 docker 鏡像


# Compile stage

FROM golang:1.11 as build-env


RUN apt-get update && \

    apt-get -y install git unzip build-essential autoconf libtool


RUN git clone https://github.com/google/protobuf.git && \

    cd protobuf && \

    ./autogen.sh && \

    ./configure && \

    make && \

    make install && \

    ldconfig && \

    make clean && \

    cd .. && \

    rm -r protobuf


RUN go get google.golang.org/grpc


RUN go get github.com/golang/protobuf/protoc-gen-go


RUN ls -la


WORKDIR /helloworld


COPY . /helloworld


RUN protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld

RUN go build -o server helloworld/greeter_server/main.go


# Making image

FROM alpine:3.8 AS host

RUN apk add --no-cache \

        ca-certificates

COPY --from=build-env /helloworld/server /

# copy any other files you need


WORKDIR /

EXPOSE 8000

CMD ["server"]


查看完整回答
反對 回復 2023-06-05
?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

您可以嘗試使用distroless基礎鏡像和多階段構建。那可能對你有幫助。



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

添加回答

了解更多

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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