1、基础镜像的选择
1.1、编译型语言的容器化(以golang为例)
#①构建简单,包含编译是的所有运行环境,但体积大
FROM golang:onbuild
EXPOSE 8080
#②构建复杂, 需执行编译动作,体积小
FROM golang:alpine
WORKDIR /app
ADD . /app
RUN cd /app && go build -o goapp
EXPOSE 8080
ENTRYPOINT ./goapp
#③构建复杂,体积更小,携带工具少,安全性更高(推荐)
FROM golang:alpine AS build-env
WORKDIR /app
ADD . /app
RUN cd /app && go build -o goapp
FROM alpine
RUN apk update && \
apk add ca-certificates && \
update-ca-certificates && \
rm -rf /var/cache/apk/*
WORKDIR /app
COPY --from=build-env /app/goapp /app
EXPOSE 8080
ENTRYPOINT ./goapp
1.2、构建工具和存储的选择
Google Container Builder和Google Container Registry
TODO
有疑问加站长微信联系(非本文作者)