CorentinTh / it-tools

Collection of handy online tools for developers, with great UX.
https://it-tools.tech
GNU General Public License v3.0
18.36k stars 2.2k forks source link

Consider Slim(Toolkit) to reduce the size of the container image #1179

Open remkolems opened 1 week ago

remkolems commented 1 week ago

What type of request is this?

Other

Clear and concise description of the feature you are proposing

I've used the Slim(Toolkit) a couple of times for my own Docker container images to reduce the size of the image considerably. Maybe it is worth a look to use it for 'it-tools' as well.

Note: I use my own locally hosted registry, that is why the image paths are slightly different than you would expect. Principle is the same.

'Slim' command

slim build --target reg.owndomain.com/hub.docker.com/corentinth/it-tools:latest

Output of 'Slim'

cmd=build info=param.http.probe message='using default probe' 
cmd=build state=started
cmd=build info=params target.image='reg.owndomain.com/hub.docker.com/corentinth/it-tools:latest' continue.mode='probe' rt.as.user='true' keep.perms='true' tags='' image-build-engine='internal' target.type='image' 
cmd=build state=image.inspection.start
cmd=build info=image id='sha256:78612560eb20365f3a59f3f912a135e54de655c485582f939826bf28a89f6e70' size.bytes='60892432' size.human='61 MB' 
cmd=build info=image.stack name='reg.owndomain.com/hub.docker.com/corentinth/it-tools:latest' id='sha256:78612560eb20365f3a59f3f912a135e54de655c485582f939826bf28a89f6e70' index='0' 
cmd=build info=image.exposed_ports list='80/tcp,80/tcp' 
cmd=build state=image.inspection.done
cmd=build state=container.inspection.start
cmd=build info=container status='created' name='slimk_2865444_20240622134836' id='52f27264e78ed4d1701c9a8feff4ce2cc4c6c78e8e0ae5360fc15fdd20b1723d' 
cmd=build info=container status='running' name='slimk_2865444_20240622134836' id='52f27264e78ed4d1701c9a8feff4ce2cc4c6c78e8e0ae5360fc15fdd20b1723d' 
cmd=build info=container message='obtained IP address' ip='172.17.0.3' 
cmd=build info=cmd.startmonitor status='sent' 
cmd=build info=event.startmonitor.done status='received' 
cmd=build info=container name='slimk_2865444_20240622134836' id='52f27264e78ed4d1701c9a8feff4ce2cc4c6c78e8e0ae5360fc15fdd20b1723d' target.port.list='32780' target.port.info='80/tcp => 0.0.0.0:32780' message='YOU CAN USE THESE PORTS TO INTERACT WITH THE CONTAINER' 
cmd=build state=http.probe.starting message="WAIT FOR HTTP PROBE TO FINISH" 
cmd=build info=continue.after mode='probe' message='no input required, execution will resume when HTTP probing is completed' 
cmd=build prompt='waiting for the HTTP probe to finish'
cmd=build state=http.probe.running
cmd=build info=http.probe.ports count='2' targets='32780,32780' 
cmd=build info=http.probe.commands count='1' commands='GET /' 
cmd=build info=http.probe.call error='none' time='2024-06-22T13:48:46Z' status='200' method='GET' target='http://127.0.0.1:32780/' attempt='1' 
cmd=build info=http.probe.summary total='1' failures='0' successful='1' 
cmd=build state=http.probe.done
cmd=build info=http.probe.crawler page='0' url='http://127.0.0.1:32780/' 
cmd=build info=http.probe.crawler page='1' url='http://127.0.0.1:32780/favicon.ico' 
cmd=build info=http.probe.crawler page='1' url='http://127.0.0.1:32780/safari-pinned-tab.svg' 
cmd=build info=http.probe.crawler page='1' url='http://127.0.0.1:32780/humans.txt' 
cmd=build info=http.probe.crawler page='1' url='http://127.0.0.1:32780/apple-touch-icon.png' 
cmd=build info=http.probe.crawler page='1' url='http://127.0.0.1:32780/favicon-32x32.png' 
cmd=build info=http.probe.crawler page='1' url='http://127.0.0.1:32780/favicon-16x16.png' 
cmd=build info=http.probe.crawler page='6' url='http://127.0.0.1:32780/assets/index-ac305cd5.css' 
cmd=build info=http.probe.crawler page='1' url='http://127.0.0.1:32780/manifest.webmanifest' 
cmd=build info=http.probe.crawler page='6' url='http://127.0.0.1:32780/assets/index-65600c6f.js' 
cmd=build info=probe.crawler.done addr='http://127.0.0.1:32780/' 
cmd=build info=event message='HTTP probe is done' 
cmd=build state=container.inspection.finishing
cmd=build state=container.inspection.artifact.processing
cmd=build state=container.inspection.done
cmd=build state=building engine=internal message="building optimized image" 
cmd=build state=completed
cmd=build info=results status='MINIFIED' by='5.97X' size.original='61 MB' size.optimized='10 MB' 
cmd=build info=results image-build-engine='internal' image.name='reg.owndomain.com/hub.docker.com/corentinth/it-tools.slim' image.size='10 MB' image.id='sha256:1a5903c6f0b4652f6d784e72adfa122ffbfdef8ebfd0243fc92b051547328cf1' image.digest='sha256:a6af9b86d8719a4957f97f11f1924aa99d012b0c225611ed063d6de34aea1485' has.data='true' 
cmd=build info=results artifacts.location='/tmp/slim-state/.slim-state/images/78612560eb20365f3a59f3f912a135e54de655c485582f939826bf28a89f6e70/artifacts' 
cmd=build info=results artifacts.report='creport.json' 
cmd=build info=results artifacts.dockerfile.reversed='Dockerfile.reversed' 
cmd=build info=results artifacts.seccomp='reg.owndomain.com-hub.docker.com-corentinth-it-tools-seccomp.json' 
cmd=build info=results artifacts.apparmor='reg.owndomain.com-hub.docker.com-corentinth-it-tools-apparmor-profile' 
cmd=build state=done
cmd=build info=commands message='use the xray command to learn more about the optimize image' 
cmd=build info=report file='slim.report.json' 
app='slim' message='GitHub Discussions' info='https://github.com/slimtoolkit/slim/discussions'
app='slim' message='Join the CNCF Slack channel to ask questions or to share your feedback' info='https://cloud-native.slack.com/archives/C059QP1RH1S'
app='slim' message='Join the Discord server to ask questions or to share your feedback' info='https://discord.gg/9tDyxYS'
app='slim' message='Join the Gitter channel to ask questions or to share your feedback' info='https://gitter.im/docker-slim/community'

Tagging and push

docker tag reg.owndomain.com/hub.docker.com/corentinth/it-tools.slim reg.owndomain.com/library/corentinth/it-tools:slim-latest
docker push reg.owndomain.com/library/corentinth/it-tools:slim-latest

Is their example of this tool in the wild?

See for CI/CD integration https://github.com/slimtoolkit/slim#integrating-slim-in-github-actions

Additional context

Result:

docker image ls | grep it-tools
reg.owndomain.com/library/corentinth/it-tools                        slim-latest             1a5903c6f0b4   31 minutes ago      10.2MB
reg.owndomain.com/hub.docker.com/corentinth/it-tools                 latest                  78612560eb20   5 weeks ago         60.9MB

The resulting image is almost 6 times reduced in size.

Validations