今天分享給大家一個工具:minid
工具下載直接訪問github搜索:minid
功能介紹
借助該工具可以優化Dockerfile,將Dockerfile的分層減少,從而達到使鏡像變小的目的
該工具主要是分析RUN,ENV等指令,將能合并分層的指令進行自動化分層,比如:
RUN cd /path/to/dir
RUN yum install Python
兩條指令可以合并為:
RUN cd /path/to/dir && yum install python
官方的實例
$ cat Dockerfile # 8 layers FROM golang:1.10-alpine3.8 AS build ENV DEP_VERSION 0.4.1 WORKDIR /go/src/github.com/orisano/gobase RUN apk add --no-cache git make mailcap tzdata RUN wget -O /usr/local/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 && chmod +x /usr/local/bin/dep RUN wget -O /usr/local/bin/depinst https://github.com/orisano/depinst/releases/download/1.0.1/depinst-linux-amd64 && chmod +x /usr/local/bin/depinst COPY Gopkg.lock Gopkg.toml ./ RUN dep ensure -vendor-only ENV CGO_ENABLED=0 ENV GO_LDFLAGS="-extldflags='-static'" RUN go build -i ./vendor/... COPY . . RUN make build $ minid # 6 layers FROM golang:1.10-alpine3.8 AS build ENV DEP_VERSION=0.4.1 WORKDIR /go/src/github.com/orisano/gobase RUN apk add --no-cache git make mailcap tzdata && wget -O /usr/local/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 && chmod +x /usr/local/bin/dep && wget -O /usr/local/bin/depinst https://github.com/orisano/depinst/releases/download/1.0.1/depinst-linux-amd64 && chmod +x /usr/local/bin/depinst COPY Gopkg.lock Gopkg.toml ./ RUN dep ensure -vendor-only ENV CGO_ENABLED=0 GO_LDFLAGS="-extldflags='-static'" RUN go build -i ./vendor/... COPY . . RUN make build