Skip to content

Instantly share code, notes, and snippets.

@Hypro999
Created December 31, 2019 06:01
Show Gist options
  • Save Hypro999/58c6522adf0eb2fe4bbe1b9deadf8bd3 to your computer and use it in GitHub Desktop.
Save Hypro999/58c6522adf0eb2fe4bbe1b9deadf8bd3 to your computer and use it in GitHub Desktop.
A simple, naive bash script to clear out intermediate docker images after building one.
#!/bin/bash
# Inspired by nnsense's answer at https://forums.docker.com/t/how-to-remove-none-images-after-building/7050/16
if [ $# -ne 1 ]; then
echo "You must enter a single valid image id or name."
else
# Assume that the image id/name is actually valid.
docker save --output /tmp/image.tar $1
docker image rm $1
docker image prune # Just an extra cleanup step while we're at it.
docker load --input /tmp/image.tar
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment