-
Notifications
You must be signed in to change notification settings - Fork 47
/
podman_images.sh
executable file
·245 lines (196 loc) · 5.06 KB
/
podman_images.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env sh
# podman_images.sh demo script.
# This script will demonstrate at an introductory level
# the use of the podman images command.
# Podman must be installed prior to running this script.
# Setting up some colors for helping read the demo output.
# Comment out any of the below to turn off that color.
bold=$(tput bold)
cyan=$(tput setaf 6)
reset=$(tput sgr0)
read_color() {
read -p "${bold}$1${reset}"
}
echo_color() {
echo "${cyan}$1${reset}"
}
setup() {
command -v podman >/dev/null
if [ $? != 0 ]; then
echo $0 requires the podman package to be installed
exit 1
fi
clear
}
intro() {
echo_color "\`podman images\` Demo"
echo
echo_color "Available at https://github.com/containers/Demos/podman_cli/podman_images.sh"
echo
}
version() {
echo_color "First check the Podman version"
echo
read_color "podman version"
echo
podman version
echo
echo
read -p "Enter to continue"
clear
}
podman_pull_images() {
echo_color "Let's pull our very first container image"
echo
read_color "podman pull alpine"
podman pull alpine
echo
echo_color "Let's look at the image"
echo
read_color "podman images"
podman images
echo
echo_color "Let's pull a busybox and nginx container image"
echo
read_color "podman pull busybox"
podman pull busybox
echo
read_color "podman pull nginx:latest"
podman pull nginx:latest
echo
echo_color "Let's look at the images"
echo
read_color "podman images"
podman images
echo
read -p "Enter to continue"
clear
}
podman_from_dockerfile() {
/bin/cat <<- "EOF" > ./Dockerfile.hello
FROM alpine
RUN apk add python3
ADD HelloFromContainer.py /home
WORKDIR HOME
CMD ["python3","/home/HelloFromContainer.py"]
EOF
/bin/cat <<- "EOF" > ./HelloFromContainer.py
#!/usr/bin/env python3
#
import sys
def main(argv):
for i in range(0,10):
print ("Hello World from Container Land! Message # [%d]" % i)
if __name__ == "__main__":
main(sys.argv[1:])
EOF
echo
echo_color "Create an image from a Dockerfile and run the container"
echo_color "Let's first look at our Dockerfile"
echo
read_color "cat ./Dockerfile.hello"
cat ./Dockerfile.hello
echo
echo_color "Let's look at our HelloFromContainer.py"
echo
read_color "cat ./HelloFromContainer.py"
cat ./HelloFromContainer.py
echo
echo_color "Create the \"hello\" image from the Dockerfile"
echo
read_color "podman build -t hello -f ./Dockerfile.hello ."
podman build -t hello -f ./Dockerfile.hello .
echo
echo_color "Run the container just to prove the container image is viable"
echo
read_color "podman run --name helloctr hello"
podman run --name helloctr hello
echo
echo_color "Commit the helloctr to make a personal image named myhello"
echo
read_color "podman commit -q --author \"John Smith\" helloctr myhello"
podman commit -q --author "John Smith" helloctr myhello
echo
echo_color "Let's look at the images"
echo
read_color "podman images"
podman images
}
podman_images() {
echo
echo_color "Let's look at what else the images command can do"
echo
echo_color "Show only the image ID's"
echo
read_color "podman images -q"
podman images -q
echo
echo_color "Show the busybox image"
echo
read_color "podman images busybox"
podman images busybox
echo
echo_color "Show the images without a table heading"
echo
read_color "podman images --noheading"
podman images --noheading
echo
echo_color "Show the images without truncating any fields"
echo
read_color "podman images --no-trunc"
podman images --no-trunc
echo
echo_color "Show the image digests"
echo
read_color "podman images --digests"
podman images --digests
echo
echo_color "Show only the ID, Repository and Tag fields"
echo
read_color "podman images --format \"table {{.ID}} {{.Repository}} {{.Tag}}\""
podman images --format "table {{.ID}} {{.Repository}} {{.Tag}}"
echo
echo_color "Show in json format"
echo
read_color "podman images --format json"
podman images --format json
echo
echo_color "Show only the alpine image using a filter"
echo
read_color "podman images --filter reference=alpine"
podman images --filter reference=alpine
echo
echo_color "Show the images sorted by size"
echo
read_color "podman images --sort size"
podman images --sort size
echo
read -p "Enter to continue"
clear
}
clean_images_and_containers() {
echo
echo_color "Time to clean up!"
read_color "podman rm -a -f"
podman rm -a -f
echo
read_color "podman rmi -a -f"
podman rmi -a -f
echo
read -p "Enter to continue"
clear
}
clean_temp_files() {
rm -rf Dockerfile.hello HelloFromContainer.py
}
setup
intro
version
podman_pull_images
podman_from_dockerfile
podman_images
clean_images_and_containers
clean_temp_files
read -p "End of Demo!!!"
echo
echo "Thank you!"