-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdock.sh
More file actions
executable file
·82 lines (56 loc) · 2.11 KB
/
dock.sh
File metadata and controls
executable file
·82 lines (56 loc) · 2.11 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
## bash-fx
if [ -z $(command -v curl) ]; then sudo apt update && sudo apt install curl -y; fi
if [ -f "/usr/local/turbolab.it/bash-fx/bash-fx.sh" ]; then
source "/usr/local/turbolab.it/bash-fx/bash-fx.sh"
else
source <(curl -s https://raw.githubusercontent.com/TurboLabIt/bash-fx/main/bash-fx.sh)
fi
## bash-fx is ready
fxHeader "🐳 Docker"
if [ -z "$1" ]; then
DOCKER_DANGLING_IMAGES=$(sudo docker images -f "dangling=true" -q)
if [ ! -z "${DOCKER_DANGLING_IMAGES}" ]; then
fxTitle "🧹 Dangling images cleanup"
fxMessage "${DOCKER_DANGLING_IMAGES}"
sudo docker rmi $(sudo docker images -f "dangling=true" -q)
fi
fxTitle "🖼 Images"
sudo docker images
fxTitle "🐋 Containers"
sudo docker container ls --all
elif [ "$1" = "new" ]; then
fxTitle "🆕 Create a new container from image"
if [ -z "$2" ] || [ -z "$3" ]; then
fxCatastrophicError "Provide the container and the image name: zzdock new container-name image-name"
fi
sudo docker container stop "$2"
sudo docker container rm "$2"
sudo docker container create -it --name "$2" "$3"
zzdock start "$2"
elif [ "$1" = "start" ]; then
fxTitle "🚪 Start+attach an existing container"
if [ -z "$2" ]; then
fxCatastrophicError "Provide the container name: zzdock start container-name"
fi
sudo docker start "$2"
zzdock attach "$2"
elif [ "$1" = "testimg" ]; then
fxTitle "👷♂️ Building a test image"
if [ ! -f "dockerfile" ]; then
fxCatastrophicError "$(pwd)/dockerfile not found!"
fi
sudo docker rmi "testimg" -f
sudo docker build --network host -t testimg .
sudo docker run -it --rm --name=testcntr testimg /bin/sh --login
elif [ "$1" = "eph" ]; then
fxTitle "🗻 Run an ephemeral instance"
sudo docker run --network host -it --rm --name=ephemeral ubuntu /bin/bash --login
elif [ "$1" = "attach" ]; then
fxTitle "🚪 Attach to a running container"
if [ -z "$2" ]; then
fxCatastrophicError "Provide the container name: zzdock attach container-name"
fi
sudo docker exec -it "$2" /bin/bash --login
fi
fxEndFooter