{"id":43069193,"url":"https://github.com/shinsenter/docker-squash","last_synced_at":"2026-01-31T13:49:16.504Z","repository":{"id":212906182,"uuid":"732577055","full_name":"shinsenter/docker-squash","owner":"shinsenter","description":"A simple shell script provides an alternative to Docker's experimental --squash option for building optimized Docker images by squashing layers.","archived":false,"fork":false,"pushed_at":"2025-09-20T12:11:06.000Z","size":32,"stargazers_count":37,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-20T14:30:01.883Z","etag":null,"topics":["build","docker","docker-image","shell-script","squash-and-merge"],"latest_commit_sha":null,"homepage":"https://shinsenter.github.io/docker-squash/","language":"Shell","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinsenter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["shinsenter"],"custom":["https://www.paypal.me/shinsenter"]}},"created_at":"2023-12-17T06:14:13.000Z","updated_at":"2025-09-20T12:11:10.000Z","dependencies_parsed_at":"2023-12-25T13:05:46.735Z","dependency_job_id":"402a99dc-ec0a-4463-9d05-4b774b0adf95","html_url":"https://github.com/shinsenter/docker-squash","commit_stats":null,"previous_names":["shinsenter/docker-squash"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shinsenter/docker-squash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-squash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-squash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-squash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-squash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinsenter","download_url":"https://codeload.github.com/shinsenter/docker-squash/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-squash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28944789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T13:02:32.153Z","status":"ssl_error","status_checked_at":"2026-01-31T13:00:07.528Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build","docker","docker-image","shell-script","squash-and-merge"],"created_at":"2026-01-31T13:49:14.093Z","updated_at":"2026-01-31T13:49:16.491Z","avatar_url":"https://github.com/shinsenter.png","language":"Shell","funding_links":["https://github.com/sponsors/shinsenter","https://www.paypal.me/shinsenter"],"categories":[],"sub_categories":[],"readme":"# docker-squash\n\nThis simple shell script provides an alternative to [Docker's experimental `--squash` option](https://docs.docker.com/engine/reference/commandline/build/#squash) for building optimized Docker images by squashing layers.\n\n## What is image squashing?\nWhen Docker builds an image, it utilizes a layered filesystem (AUFS). Each command in the Dockerfile adds a new layer that contains only the changes from the previous layer. This makes builds very fast since only changed files have to be copied.\n\nHowever, the layered filesystem also results in larger image sizes since each layer contains duplicate files. Squashing combines these layers into a single layer, reducing storage space and often improving runtime performance by decreasing mount points.\n\n## Benefits over \"docker build --squash\"\nThe `--squash` option provided by Docker squashes all layers into one, reducing image size. However, it also discards all previous instructions like ENV, LABEL, etc.\n\nThis script also squashes image layers but keeps ENV, ARG, LABEL and other metadata from the original image.\n- Retains user, workdir, and other runtime configurations\n- Results in smaller image sizes by combining redundant layers\n- Faster lookups at runtime by reducing layer mount points\n\nIn other words - smaller images but preserving more of the original image definition!\n\n## Download\n\nYou can download [the docker-squash.sh script](https://github.com/shinsenter/docker-squash/raw/main/docker-squash.sh) from this GitHub repository and save it to your local file system.\n\nAlternatively, you can run these commands with superuser (root) privileges to download the script to the system directory /usr/local/bin using curl:\n\n```shell\nsudo curl -sL https://github.com/shinsenter/docker-squash/raw/main/docker-squash.sh -o /usr/local/bin/docker-squash.sh\nsudo chmod +x /usr/local/bin/docker-squash.sh\n```\n\n## Usage\n```shell\ndocker-squash.sh \u003csource_image\u003e [docker build options]\n```\n\nWhere:\n- `source_image` - The original image ID or `name:tag` to be squashed\n- `docker build options` - Additional build options like `--build-arg`, `--label`, etc.\n\n### Use-cases:\n\nSquashing existing images or Dockerfiles is seamless while providing size and performance benefits.\n\n#### Squash an existing image to reduce its size:\n```shell\ndocker pull php:apache\ndocker-squash.sh php:apache -t php:apache-squashed\ndocker images | grep -F 'apache'\n# Original image size: 515MB\n# Squashed image size: 505MB\n```\n\n#### Inject pre-squash script which is executed before squashing:\nYou can add your shell script to a build argument named `PRESQUASH_SCRIPTS` and execute as root user. It may be useful to clean up the source image before squashing.\n```shell\ndocker pull php:apache\ndocker-squash.sh php:apache \\\n    --build-arg PRESQUASH_SCRIPTS='rm -rf /tmp/* /var/lib/apt/lists/*; apt-get -y autoremove --purge $PHPIZE_DEPS *-dev' \\\n    -t php:apache-squashed\ndocker images | grep -F 'apache'\n# Original image size: 515MB\n# Squashed image size: 275MB\n```\n\n#### Specify target platform to squash multi-architecture images:\n```shell\ndocker pull --platform linux/arm64 ubuntu:jammy\ndocker-squash.sh ubuntu:jammy -t ubuntu:jammy-squashed --platform linux/arm64\ndocker images | grep -F 'jammy'\n# Original image size: 69.2MB\n# Squashed image size: 67.2MB\n```\n\n#### Squash image built straight from a Dockerfile:\n```shell\ndocker-squash.sh /home/my-project/Dockerfile -t my-project:squashed\n```\n\n## Pros and Cons\n\n#### Pros:\n- Smaller image size\n- Faster runtime performance\n- Obfuscates build details\n- Retains Dockerfile metadata\n\n#### Cons:\n- Slower rebuild time\n- Can inhibit debugging capabilities\n- Loss of Docker cache and remote build benefits\n\n## Support this project\nIf you find this tool helpful and wish to support continued development, I welcome donations or other contributions:\n\n### Donate\nI appreciate monetary contributions via [PayPal](https://www.paypal.me/shinsenter) to help fund development costs. Your support is greatly appreciated.\n\n### Contribute\nThis is open source software. If you have suggestions, spot issues, or can contribute code changes, please open GitHub issues or pull requests on this project repository. I welcome community input to help expand capabilities and fix problems!\n\nTogether we can build better tools for working with Docker. Thank you!\n\n* * *\n\nFrom Vietnam 🇻🇳 with love.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinsenter%2Fdocker-squash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinsenter%2Fdocker-squash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinsenter%2Fdocker-squash/lists"}