Follow
GREPPER
SEARCH SNIPPETS
PRICING
FAQ
USAGE DOCS
INSTALL GREPPER
Log In
All Languages
>>
Shell/Bash
>>
how to delete docker images older than x days from docker hub using a shell script serverfault
“how to delete docker images older than x days from docker hub using a shell script serverfault” Code Answer’s
how to delete docker images older than x days from docker hub using a shell script serverfault
shell by
Lucky LyreDragonbird
on Jul 18 2020
Donate
1
#!/bin/bash #Script will delete all images in all repositories of your docker hub account which are older than 'X' days set -e # set your username, password and no. of 'X' days value in below lines. #UNAME="YOUR_USERNAME" #UPASS="YOUR_PASSWORD" #X="YOUR_DAYS_VALUE" # pass username,password and no of 'X' days value from terminal as below line. # ./docker-images-remove-script.sh <username> <password> <30> UNAME=$1 UPASS=$2 X=$3 # get token to be able to talk to Docker Hub TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token) #echo $TOKEN echo # get list of repos for that user account echo "List of Repositories in '${UNAME}' Docker Hub account." sleep 5 REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" "https://hub.docker.com/v2/repositories/${UNAME}/?page_size=10000" | jq -r '.results|.[]|.name') #echo "$REPO_LIST" count=1 for rep in ${REPO_LIST} do echo S.No: $count RepoName: $rep count=`expr $count + 1` done echo sleep 5 echo echo "Identifying and deleting images which are older than $X days in '${UNAME}' docker hub account." sleep 5 #NOTE!!! For deleting specific repositories images please include only those repositories in for-loop, like below for-loop which has repos mysql and mymongo #for i in mysql mymongo for rep in ${REPO_LIST} do # get total no. of images & their count for a repo Images=$(curl -s -H "Authorization: JWT ${TOKEN}" "https://hub.docker.com/v2/repositories/$UNAME/$rep/tags/") ImageCount=$(echo $Images | jq -r '.count') echo "Total no of Images in '$UNAME/$rep' repository are: $ImageCount" pages=`expr $ImageCount / 100 + 1` echo "No pages to iterate are: $pages" sleep 5 for (( p=1; p<=$pages; p++ )) do echo "Looping Through '$rep' repository in '${UNAME}' account." IMAGES=$(curl -s -H "Authorization: JWT ${TOKEN}" "https://hub.docker.com/v2/repositories/${UNAME}/${rep}/tags/?page_size=100&page=$p") IMAGE_TAGS=$(echo $IMAGES | jq -r '.results|.[]|.name') count1=1 # build a list of images from tags for tag in ${IMAGE_TAGS} do echo Iteration no. is: $p echo "S.No: $count1. RepoName: '$rep' ImageTag: $tag" count1=`expr $count1 + 1` sleep 5 # Get last_updated_time updated_time=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${rep}/tags/${tag}/?page_size=100 | jq -r '.last_updated') echo "Image build date and time is : $updated_time" datetime=$updated_time timeago=''$X' days ago' #echo $timeago dtSec=$(date --date "$datetime" +"%Y%m%d") taSec=$(date --date "$timeago" +"%Y%m%d") dt_Sec=$(date --date "$datetime" +"%Y-%m-%d") ta_Sec=$(date --date "$timeago" +"%Y-%m-%d") echo "INFO: Date on which this image was build: $dt_Sec" echo "INFO: $X days earlier date from today is: $ta_Sec" sleep 5 if [ $dtSec -lt $taSec ] then echo "This image '${UNAME}/${rep}:${tag}' is older than $X days, deleting this image." #### Note! TO delete an image please uncomment below line. #### curl -s -X DELETE -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${rep}/tags/${tag}/ else echo "This image '${UNAME}/${rep}:${tag}' is within $X days time range, keep this image." fi done done echo done echo "Script execution ends here."
Source:
serverfault.com
How to delete docker images from docker hub using a shell script serverfault
shell by
Lucky LyreDragonbird
on Jun 21 2020
Donate
0
#!/bin/bash set -e # set username and password UNAME="YOUR_USERNAME" UPASS="YOUR_PASSWORD" # get token to be able to talk to Docker Hub TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token) # get list of namespaces accessible by user (not in use right now) #NAMESPACES=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/namespaces/ | jq -r '.namespaces|.[]') #echo $TOKEN echo # get list of repos for that user account echo "List of Repositories in ${UNAME} Docker Hub account" sleep 5 REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/?page_size=10000 | jq -r '.results|.[]|.name') echo $REPO_LIST echo # build a list of all images & tags for i in ${REPO_LIST} do # get tags for repo IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${i}/tags/?page_size=10000 | jq -r '.results|.[]|.name') # build a list of images from tags for j in ${IMAGE_TAGS} do # add each tag to list FULL_IMAGE_LIST="${FULL_IMAGE_LIST} ${UNAME}/${i}:${j}" done done # output list of all docker images echo echo "List of all docker images in ${UNAME} Docker Hub account" sleep 10 for i in ${FULL_IMAGE_LIST} do echo ${i} done sleep 10 echo echo "Identifying and deleting images which are older than 50 days in ${UNAME} docker hub account" sleep 10 for i in ${REPO_LIST} #NOTE!!! For deleting Specific repositories images please include only those repositories in for loop like below for loop which has repos mygninx and mykibana #for i in mynginx mykibana do # get tags for repo echo echo "Looping Through $i repository in ${UNAME} account" IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${i}/tags/?page_size=10000 | jq -r '.results|.[]|.name') # build a list of images from tags for j in ${IMAGE_TAGS} do echo # add last_updated_time updated_time=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${i}/tags/${j}/?page_size=10000 | jq -r '.last_updated') echo $updated_time datetime=$updated_time timeago='50 days ago' dtSec=$(date --date "$datetime" +'%s') taSec=$(date --date "$timeago" +'%s') echo "INFO: dtSec=$dtSec, taSec=$taSec" if [ $dtSec -lt $taSec ] then echo "This image ${UNAME}/${i}:${j} is older than 50 days, deleting this image" ## Please uncomment below line to delete docker hub images of docker hub repositories #curl -s -X DELETE -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${i}/tags/${j}/ else echo "This image ${UNAME}/${i}:${j} is within 50 days time range, keep this image" fi done done echo "Script execution ends"
Source:
serverfault.com
Shell/Bash answers related to “how to delete docker images older than x days from docker hub using a shell script serverfault”
delete all docker images
delete docker image repository none
docker delete all images
docker delete container and image
docker delete existing volumes
docker delete image
docker for mac remove unnamed images
docker purge all
docker remove all containers and images
docker remove all image
docker remove all images
docker remove all images powershell
docker remove dangling images
how to delete dangling docker images
how to delete image docker
how to delete images older than x days from docker hub
how to delete repository in docker hub
how to remove all docker container at once
how to remove docker images
remove all docker iamges commandl
remove all docker images
remove docker image
remove docker images
remove downloaded docker images
remove unused images docker manually
remove unused images docker manually version 1.12.6
use curl to delete an image from docker hub
Shell/Bash queries related to “how to delete docker images older than x days from docker hub using a shell script serverfault”
How to delete docker images older than x days from docker hub using a shell script serverfault
How to delete docker images from docker hub using a shell script serverfault
Learn how Grepper helps you improve as a Developer!
INSTALL GREPPER FOR CHROME
More “Kinda” Related Shell/Bash Answers
View All Shell/Bash Answers »
stop all container in docker
Got permission denied while trying to connect to the Docker daemon socket
remove all docker images
docker stop all
remove all images docker
docker remove all images
docker remove all containers
run docker redis localhost
remove docker volume
docker remove images without tag
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
docker delete all containers
remove docker container
docker stop all containers
docker clean unused images
docker-compose force rebuild
install docker-compose ubuntu 20
docker tail logs
how to restart docker linux
make docker sudo less
Amazon Linux 2 AMI install docker
docker post installation steps linux
how to install docker ubuntu
failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
delete all docker images
windows delete all docker images
macbook Couldn't connect to Docker daemon - you might need to run `docker-machine start default`
docker delete all images
docker for mac remove unnamed images
add user to docker group
docker log tail
how to stop docker in ubuntu
docekr enter container
portainer instal
docker to sudoers
how to expose docker api over tcp
docker install nano
remove stopped containers
space in dock mac
install docker compose
remove all containers docker
rancher docker reset password
debian docker
docker how to echo env variable in bash
Start the Docker daemon
docker remove all dead containers
docker untar
Failed to start Docker Application Container Engine
how to delete docker images older than x days from docker hub using a shell script serverfault
check if docker is running
install docker on ubuntu 18.04
docker remov all running containers
docker interactive shell
how to reload docker nginx
Error response from daemon: open \\.\pipe\docker_engine_linux: The system cannot find the file specified.
install docker machine ubuntu
how check status docker in ubuntu
ubuntu minimize window by clicking on dock
how to install and enable docker on command line with EC2 instance
install vi editor ubuntu dockerfile
stop docker container
write command docker without need write sudo
docker prune system
docker-machine create digitalocean
copy file from docker container to host
docker-machine install mac brew
remove docker images
how to delete images older than x days from docker hub
how to upgrade jenkins in docker
intall docker ubuntu command
running docker in wsl
start service docker on linux
install docker centos 8
how to bash into docker container
docker-compose permission denied
docker-compose install in centos 7
docker ps view command
WSL connect docker daemon to docker for windows
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
how to start docker
docker hello world
docker force remove container
docker run restart on boot
windows docker update clock
docker remove none images
pod: command not found
docker compose down
instalar docker compose ubuntu
docker remove dangling images
can't kill docker container
get-docker sh
copy docker image from one machine to another
install docker ubuntu
docker compose run
centos install docker-compose
docker remove image
docker.service: Failed with result 'exit-code'
docker check running containers
grep docker logs
docker mssql
docker active log
how to delete docker containers
customize dock in ubuntu
add application to ubuntu dock
docker extract file from image
Package 'docker-ce' is not installed, so not removed
docker run ubuntu container
install docker
docker purge all
docker container logs
docker delete container and image
docker current version
rancher get started
how to install docker on ubuntu
docker install ubuntu
docker clear cache
docker install in centos u7
how to create a host driver in docker
docker remove not running containers
install docker on ubuntu 20.04
The repository 'https://download.docker.com/linux/ubuntu focal Release' does not have a Release file
docker dangling images
install rancher
install flask dockerfile
docker run restart always
docker run name
docker on centos7
docker compose up only one service
docker pack image to file
linux get docker compose logs
docker remove all volume
Failed to start docker.service: Unit docker.service is masked
docker daemon is not running
how to delete image docker
centos 7 install docker compose
remove unused images docker manually
install docker on wsl
docker remove all images powershell
copy local docker image to kind cluster
docker installation
Docker permission denied
net start docker service
docker run npm install express syntax
docker stack deploy
docker node alpine
docker build from github repository
how to check if i have docker installed
docker remove all exited containers
how to start docker in ubuntu
docker delete image
how to stop docker
docker-compose install centos 8
docker clean logs
docker sudo how to add user
docker-compose command not found ubuntu 18.04
list stopped containers
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:
remove docker image
docker remove all image
docker compose install ubuntu
docker help
docker build
docker remove container
docker.service: Unit entered failed state.
install composer in dockerfile
Install ansible in docker
dial unix /var/run/docker.sock: connect: permission denied
helm docker generate doc
display docker networks
how to test if docker is running from boot
docker getting-started
install docker-compose in centos 8
bash: docker-compose: command not found
Error initializing network controller: Error creating default "bridge" network: Failed to program NAT chain: ZONE_CONFLICT: 'docker0' already bound to a zone
docker redis
docker-compose installation
docker commit
docker exc into mongo shell
keycloak docker
rename a running docker container
docker swarm deploy
docker compose no space left on device
upgrade docker compose windows
docker run command on container
how to setup dockers on aws
how to clear docker-compose logs
docker image load
docker-compose install
docker run jenkins
how to install docker in ubuntu using terminal
docker force a rebuild
Composer install with dockerfile
install docker debian
why installing pandas take time in docker
simple nodejs dockerfile
docker remove exited containers
join docker swarm
kubectl create pod
install docker in ubuntu
commit container to image
docker compose installation
install docker linux
how to delete dangling docker images
docker NoRouteToHostException: No route to host (Host unreachable)
install flask dockerfile freeze
dockerfile for vuejs
docker manjaro
install hass.io docker raspberry pi
installing docker on mac using brew
remove unused images docker manually version 1.12.6
docker install manjaro
docker create
docker display stopped containers
docker create image from tar file
docker for linux
dockerfile for NGINX vuejs
docker alpine create user and group
docker push image
docker command to login with user name and pass word
command not found: docker-compose
docker compose keep container running
push image to docker hub
pushing image to docker hub
docker see containers full command
ubuntu install docker
bash not found docker
docker copy folder to container
docker container
docker remove
kind load docker-image command
docker compose install centos 8
kubectl run pod
Can't start my virtualBox machine after installing Docker on Windows
attributeerror module 'platform' has no attribute 'linux_distribution' ubuntu 20.04 docker-compose
delete docker logs linux
remove all unused volumes docker
gitlab docker runner
can't find tty file in docker mac
raspbian OS 64 docker
git install on alpine
mongodb database not connected docker
remove all docker iamges commandl
docker --restart example
sudo apt-get install docker-ce docker-ce-cli containerd.io command not working
show ip in docker
docker run opendistro elasticsearch
create docker swarm
docker container with static apache
where is docker images stored windows wsl2
get docker container version from inside container
how to pull private docker image in helm charts
rancher getting started
docker compose
borrar images docker
docker image is not reseting
install pip dockerfile
docker save in windows
docker windows browser can't see the server
docker ubuntu installation
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 192.168.65.1:53: no such host. in windows
list dockers docker compose
centos start docker
ERROR: Get https://registry-1.docker.io/v2/
docker engine install ubuntu
how to pass docker hub credentials for k8s pods
ubuntu dock setting
how to create docker image from custom filename
docker cp volume
deploy docker on digital ocean
dockerfile expose udp port
how to create docker for wordpress container
how to create docker container on tag creation using gitlab ci
docker no space left on device ubuntu but only 75% use?
docker install
install docker desktop on server 2019
docker update all images
docker splunk
get docker image from docker hub
install docker compose in suse linux
start jupyter remote docker locally
check if docker is installed ubuntu
bcrypt fails during docker compose
start docker service on windows
whats up with docker compose and orphan containers
how to know what container is using a volume?
rhel 8 docker 19.03
got permission denied docker
docker unable to push repo access denied
docker laravel configuration ubuntu
Reading state information... Done E: Unable to locate package docker-ce
docker.credentials.errors.StoreError: Credentials store docker-credential-desktop.exe exited with ""
entrypoint vs command docker-compose
docker toolbox windows clean
docker compose service wait for forever
pass vairalbe into string dockerfile
add a project in rancher
adoptopenjdk to linux docker image
Target DEP-11-icons-small (stable/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-groovy.list:1 and /etc/apt/sources.list.d/docker-ce.list:1
how to remove all docker container at once
install docker on ubuntu with
docker quickstart terminal windows
docker image layer storage windows
remove docker volumes stack overflow
mysql backup dump docker file
interface docker
add spacer to dock macos
kong en docker
docker run teamcity
docker entrypoint how not finish container
ubuntu 18.04 create folders in dock
insert bash command to docker-compose file
install docker on manjaro linux
use curl to delete an image from docker hub
how to pass linux command in in docker-compose yaml file
download docker ubuntu
install docker-compose coreos
-v /var/run/docker.sock jenkins/jenkins
Install docker EE without internet
docker cachebust
docker compose rebuild image
copying files in Docker to directory gives error
container has runAsNonRoot and image has non-numeric user
tensorflow docker hub
docker compose limit logs
latte dock application launcher shortcut
how to execute docker command in shell script
docker delete existing volumes
run docker container with ansible
log to file docker overflow
containerDS Desktop tool for docker images
attching to milticontainer pod
docker compose install manjaro
docker image with wget
install tyk docker
multiple run dockerfile
How to delete docker images from docker hub using a shell script serverfault
how to run r in docker
docker-compose update code without using build again
setting docker as a non root user
install docker compose homebrew
docker-containers-noroutetohostexception-host-is-unreachable
free dock for linux
nagiosPi docker-compose
docker wsl2 vmmem
connect hub docker private with cloud foundry
run katalon docker image
docker compose exec compose
install docker-machine-driver-hyperkit
how to pass docker hub credentials for helm values.yaml
docker why my container start on reboot
postgresql not connected docker
how to copy a dockerimage to different machine
not reinstalling packages on docker build
docker-machine –version
install docker in suse linux
ubuntu 20.04 dash is conflicting with dock
install docker on ubuntu
install docker centos 7
install docker debain
docker how to run existing container
apt install docker
install docker compose ubuntu 20.04
get log from a docker machine
brew install docker
docker compose entrypoint
how to point docker to github
install docker in linux
sudo ufw status Status: inactive
adding jars to classpath in linux
linux install pip
installing react router dom with yarn
running docker in wsl
ubuntu find file with text
bash command to empty textfile
access windows files from windows ubuntu
revert commit git
ssh without password
git config core.autocrlf true
how to kill a process in linux
how to install cab file in ubuntu
how to change branch name
Browse Other Code Languages
Abap
ActionScript
Assembly
BASIC
C
Clojure
Cobol
C++
C#
CSS
Dart
Delphi
Elixir
Erlang
Fortran
F#
Go
Groovy
Haskell
Html
Java
Javascript
Julia
Kotlin
Lisp
Lua
Matlab
Objective-C
Pascal
Perl
PHP
PostScript
Prolog
Python
R
Ruby
Rust
Scala
Scheme
Shell/Bash
Smalltalk
SQL
Swift
TypeScript
VBA
WebAssembly
Whatever