文章插图
今天分享给大家一个工具: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 layersFROM golang:1.10-alpine3.8 AS buildENV DEP_VERSION 0.4.1WORKDIR /go/src/github.com/orisano/gobaseRUN apk add --no-cache git make mailcap tzdataRUN wget -O /usr/local/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 && chmod +x /usr/local/bin/depRUN wget -O /usr/local/bin/depinst https://github.com/orisano/depinst/releases/download/1.0.1/depinst-linux-amd64 && chmod +x /usr/local/bin/depinstCOPY Gopkg.lock Gopkg.toml ./RUN dep ensure -vendor-onlyENV CGO_ENABLED=0ENV GO_LDFLAGS="-extldflags='-static'"RUN go build -i ./vendor/...COPY . .RUN make build$ minid # 6 layersFROM golang:1.10-alpine3.8 AS buildENV DEP_VERSION=0.4.1WORKDIR /go/src/github.com/orisano/gobaseRUN 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/depinstCOPY Gopkg.lock Gopkg.toml ./RUN dep ensure -vendor-onlyENV CGO_ENABLED=0 GO_LDFLAGS="-extldflags='-static'"RUN go build -i ./vendor/...COPY . .RUN make build
【借助工具优化Dockerfile分层】
推荐阅读
- 性能优化技巧 - 查找
- 定制优化Nextcloud镜像
- centos7中利用logrotate工具切割tomcat日志
- Ansible自动化工具快速入门实践
- 爬山用的工具有哪些呢
- 大家常用哪个MySQL客户端工具,除了命令行那个mysql之外?
- mysql查询太慢,我们如何进行性能优化?
- 网络/命令行抓包工具tcpdump详解
- 这可能是网上最全的 Docker 工具集合
- Centos7系统内核优化脚本