【发布时间】:2019-07-11 14:03:55
【问题描述】:
我有一些使用 gRPC/golang 进行通信的服务器和客户端。现在我想将我的应用程序容器化,但是包含 goland 执行和 grpc 支持的 docker 映像的大小更大(超过 1GB)。我想减小 docker 图像的大小。
所需的 golang 版本为 1.9 及更高版本。这是给出的 Dockerfile 脚本。如果有其他方法请建议。
FROM golang:1.11
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
CMD ["go", "run", "helloworld/greeter_server/main.go"]
【问题讨论】:
-
当前目录的内容是什么?您是否尝试使用
stage构建?你用过.dockerignore吗? -
当前目录是 grpc 示例,可在 grpc 存储库 [github.com/grpc/grpc-go/tree/master/examples] 中找到。我不知道舞台搭建。可以提供资源吗?
-
你需要从上下文中排除你不需要的东西,你可以通过
COPY只需要directroy或使用.dockerignore文件来完成。以下是关于多阶段构建blog.alexellis.io/mutli-stage-docker-builds 的一些信息 -
你能分享你从哪张图片开始的吗?
Dockerfile中的FROM -
@Matteo 目前我是从 golang 1.11 开始,但我已经看到它是从 debian 开始的,它们可能体积很小,但我不太了解。