Skip to content

Instantly share code, notes, and snippets.

@csloz
Last active October 22, 2019 06:50
Show Gist options
  • Save csloz/0b1e1161bf6c6c77c3413437039c5c90 to your computer and use it in GitHub Desktop.
Save csloz/0b1e1161bf6c6c77c3413437039c5c90 to your computer and use it in GitHub Desktop.
Docker update script to ensure docker containers are updated, dangling unused containers are nuked, and unused images purged.
#!/bin/bash
# Ensure docker is updated, and dangling / unused images are purged
# Restarts containers when done.
# Author: L. Sheed
# Delete all dangling (unused) images
docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi
#prune anything unused and remaining
docker image prune -fa
# Update all docker containers
docker images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 docker pull
#restart any killed containers
docker-compose up -d --remove-orphans
docker restart $(docker ps -a -q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment