Docker-slim
Instruction platform: Linux
- Github: docker-slim
Download from here: https://dockersl.im/install.html
Click the Linux version to download the package.
You can copy and paste it into your /user/bin
folder.
sudo cp dist_linux/* /usr/bin/
Or you can use terminal to install it.
curl -sL https://raw.githubusercontent.com/docker-slim/docker-slim/master/scripts/install-dockerslim.sh | sudo -E bash -
Usage
--include-path
--http-probe
Steps
Let's pull the docker image first.
$ docker pull nginx:latest
latest: Pulling from library/nginx
a2abf6c4d29d: Already exists
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
$ docker images nginx:latest
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 3 weeks ago 141MB
As we can see, the image size is 141MB before we start to optimize it.
Then let's use docker-slim to build a new iamge.
$ docker-slim build --target nginx:latest
docker-slim: message='join the Gitter channel to ask questions or to share your feedback' info='https://gitter.im/docker-slim/community'
docker-slim: message='join the Discord server to ask questions or to share your feedback' info='https://discord.gg/9tDyxYS'
docker-slim: message='Github discussions' info='https://github.com/docker-slim/docker-slim/discussions'
cmd=build info=param.http.probe message='using default probe'
cmd=build state=started
cmd=build info=params keep.perms='true' tags='' target.type='image' target='nginx:latest' continue.mode='probe' rt.as.user='true'
cmd=build state=image.inspection.start
cmd=build info=image id='sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85' size.bytes='141479488' size.human='142 MB'
cmd=build info=image.stack index='0' name='nginx:latest' id='sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85'
cmd=build info=image.exposed_ports list='80'
cmd=build state=image.inspection.done
cmd=build state=container.inspection.start
cmd=build info=container status='created' name='dockerslimk_561458_20220125053612' id='7b9b61b8bb0e6a16e9ac740592b0ca3d110b8bdd34fa70386312ae8dc254a391'
time="2022-01-25T13:36:12+08:00" level=error msg="channel.Client.Read: read error (read tcp 127.0.0.1:43352->127.0.0.1:49172: read: connection reset by peer), exiting..."
time="2022-01-25T13:36:12+08:00" level=error msg="channel.NewCommandClient: channel verify error = read tcp 127.0.0.1:43352->127.0.0.1:49172: read: connection reset by peer"
cmd=build info=cmd.startmonitor status='sent'
cmd=build info=event.startmonitor.done status='received'
cmd=build info=container name='dockerslimk_561458_20220125053612' id='7b9b61b8bb0e6a16e9ac740592b0ca3d110b8bdd34fa70386312ae8dc254a391' target.port.list='49173' target.port.info='80/tcp => 0.0.0.0:49173' 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='1' targets='49173'
cmd=build info=http.probe.commands count='1' commands='GET /'
cmd=build info=http.probe.call error='none' time='2022-01-25T05:36:29Z' status='200' method='GET' target='http://127.0.0.1:49173/' 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:49173/'
cmd=build info=probe.crawler.done addr='http://127.0.0.1:49173/'
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 message=building optimized image
cmd=build state=completed
cmd=build info=results status='MINIFIED' by='12.09X' size.original='142 MB' size.optimized='12 MB'
cmd=build info=results image.name='nginx.slim' image.size='12 MB' has.data='true'
cmd=build info=results artifacts.location='/tmp/docker-slim-state/.docker-slim-state/images/605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85/artifacts'
cmd=build info=results artifacts.report='creport.json'
cmd=build info=results artifacts.dockerfile.reversed='Dockerfile.fat'
cmd=build info=results artifacts.dockerfile.optimized='Dockerfile'
cmd=build info=results artifacts.seccomp='nginx-seccomp.json'
cmd=build info=results artifacts.apparmor='nginx-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'
docker-slim: message='join the Gitter channel to ask questions or to share your feedback' info='https://gitter.im/docker-slim/community'
docker-slim: message='join the Discord server to ask questions or to share your feedback' info='https://discord.gg/9tDyxYS'
docker-slim: message='Github discussions' info='https://github.com/docker-slim/docker-slim/discussions'
$ docker images nginx.slim
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx.slim latest cbe6ce079aa2 15 seconds ago 11.7MB
Let's check it that it shows the size becoming to 11.7 MB size.
Note
Test with ubuntu:20.04, we need to use --http-probe=false
docker-slim build --http-probe=false ubuntu:20.04