ping each running container
docker ps -q | xargs docker inspect --format=' {{.NetworkSettings.IPAddress}}' | xargs -l1 ping -c1
function basher() {
if [[ $1 = ' run' ]]
shift
/usr/bin/docker run -e HIST_FILE=/root/.bash_history -v $HOME /.bash_history:/root/.bash_history " $@ "
else
/usr/bin/docker " $@ "
fi
}
alias docker=basher
delete all containers (running and stopped)
docker ps -a -q | xargs --no-run-if-empty docker rm -f
delete selected containers (exited | running | restarting)
docker ps -a -q --filter status=exited | xargs --no-run-if-empty docker rm
list all containers with a non-zero error code
comm -3 <( docker ps -a -q --filter=status=exited | sort) <( docker ps -a -q --filter=exited=0 | sort) | xargs --no-run-if-empty docker inspect > error_containers
dry run, and remove unmounted volumes
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --privileged dockerinpractice/docker-cleanup-volumes --dry-run
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --privileged dockerinpractice/docker-cleanup-volumes
watch -n .2 curl test.com
siege test.com
Create Postgres volume container
docker run --name dbdata postgres echo " Data-only container for postgres"
Use Postgres volume container
docker run -d --volumes-from dbdata --name db1 postgres
Backup Postgres volume container
docker run --rm --volumes-from dbdata -v $( pwd) :/backup debian tar cvf /backup/backup.tar /var/lib/postgresql/data