This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
bash_docker_aliases
46 lines (39 loc) · 1.67 KB
/
bash_docker_aliases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Some useful commands to use docker.
# Author: wrfly <[email protected]>
# Updated at: 2017-3-8
# clean stopped containers
function docker-clean(){
sdiff <(docker ps -qa|sort) <(docker ps -q|sort) | grep '<' | cut -d ' ' -f 1 | for c in `xargs`;do sudo docker rm -v $c; done
# diff --side-by-side --suppress-common-lines <(docker ps -qa|sort) <(docker ps -q|sort) | cut -d' ' -f1
# sdiff <(docker ps -qa|sort) <(docker ps -q|sort) | grep '<' | cut -d ' ' -f 1
# comm <(sudo docker ps -qa|sort) <(sudo docker ps -q|sort) --output-delimiter ':' | grep -E '^[^:]' --color=no
}
# about inspect
alias docker-pid="sudo docker inspect --format '{{.State.Pid}}'"
alias docker-ip="sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}'"
# get into the container
alias de='docker-enter'
function docker-enter() {
CID=$1
# bash > ash > sh
SHELL=sh
for _SHELL in bash ash sh;do
sudo docker cp $CID:/bin/${_SHELL} - &> /dev/null && SHELL=${_SHELL} && break
done
sudo docker exec -ti -e TERM=xterm $CID $SHELL
}
# docker stop and remove
function drm() {
docker stop $1 && docker rm $1
}
# clean unused images
alias docker-clean-unused-images="sdiff <(sudo docker images -q|sort) <(sudo docker ps -qa | xargs sudo docker inspect --format '{{ .Image }}' | cut -d ':' -f2 | cut -c 1-12 | sort -u) | grep '<' | cut -d ' ' -f 1 | xargs sudo docker rmi"
# remove <none> images
function docker-remove-none-images() {
images=$(sudo docker images | grep '<none>' | awk '{print $3}')
for i in `echo $images`;do
sudo docker rmi $i
done
}
# ctop (container top)
alias ctop='docker run -ti --name ctop --rm -v /var/run/docker.sock:/var/run/docker.sock wrfly/ctop:latest'