# 从0究极缩减镜像大小
# 安装docker-slim
curl https://oss.odboy.cn/blog/files/docker-slim/dist_linux_1.40.11.tar.gz
tar -xzvf dist_linux_1.40.11.tar.gz
mv -f ./dist_linux/* /usr/bin/
chmod +x /usr/bin/docker-slim*
rm -rf ./dist_linux
1
2
3
4
5
2
3
4
5
# 测试镜像
[root@easzlab ~]# docker images|grep 'easzlab.io.local:5000/springboot-standard-demo'
easzlab.io.local:5000/springboot-standard-demo release_202410152011 51df0e8d9bcb 7 hours ago 1.05GB
1
2
2
# 执行命令
- /etc:配置文件
- /usr/:用户二进制文件和程序
- /sbin/:系统二进制文件
- /root/:root 用户的主目录
- /bin/:基本命令二进制文件
- /bin/bash:Bash shell
- /usr/local/java/:Java运行库
- /home/admin/:应用所在目录
- /opt/devops-app-control/:应用生命周期控制脚本所在目录
docker-slim build \
--target easzlab.io.local:5000/springboot-standard-demo:release_202410152011 \
--tag easzlab.io.local:5000/springboot-standard-demo:release_202410152011.slim \
--http-probe=false \
--include-path=/etc \
--include-path=/usr/ \
--include-path=/sbin/ \
--include-path=/root/ \
--include-path=/bin/ \
--include-bin=/bin/bash \
--include-path=/usr/local/java/ \
--include-path=/home/admin/ \
--include-path=/opt/devops-app-control/ \
--exec "curl checkip.amazonaws.com"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 镜像测试
写错了好几次,就不截图了
[root@easzlab ~]# docker run -itd easzlab.io.local:5000/springboot-standard-demo:release_202410152011.slim
d4a984153198b0b9422f3b50f7d001b8d4516a49a1afc65e1a5b0e4745b54360
[root@easzlab ~]# docker exec -it d4a984153198b0b9422f3b50f7d001b8d4516a49a1afc65e1a5b0e4745b54360 bash
[root@d4a984153198 springboot-standard-demo]# ./start_do.sh
[root@d4a984153198 springboot-standard-demo]# curl http://127.0.0.1:21800/monitor/healthCheck
1
1
2
3
4
5
6
2
3
4
5
6
# 最终效果
就问你夸张不夸张?