@@ -26,6 +26,16 @@ function docker_remove_image() {
26
26
docker rmi " ${image} " || true
27
27
}
28
28
29
+ function trap_handler() {
30
+ local dind_container=" $1 "
31
+
32
+ if [[ " ${remove_dind_container} " == " true" ]]; then
33
+ docker rm -f " ${dind_container} " & > /dev/null
34
+ else
35
+ echo " DinD container NOT removed, please remove it manually"
36
+ fi
37
+ }
38
+
29
39
function main() {
30
40
local dind_container=" $1 "
31
41
local images_file=" $2 "
@@ -47,10 +57,11 @@ function main() {
47
57
docker_save_image " ${first_image} " " ${output_dir} "
48
58
done < " ${images_file} "
49
59
60
+ export remove_dind_container=" true"
50
61
# as this function maybe called multiple times, we need to ensure the container is removed
51
- trap " docker rm -f " ${dind_container} " &> /dev/null " RETURN
62
+ trap " trap_handler ${dind_container} " RETURN
52
63
# we're using set -e so the trap on RETURN will not be executed when a command fails
53
- trap " docker rm -f " ${dind_container} " &> /dev/null " EXIT
64
+ trap " trap_handler ${dind_container} " EXIT
54
65
55
66
# start DinD container
56
67
# In order to avoid the src bind mount directory (./images/) ownership from changing to root
@@ -70,6 +81,16 @@ function main() {
70
81
fi
71
82
done
72
83
84
+ # As hook-docker uses the overlay2 storage driver the DinD must use the overlay2 storage driver too.
85
+ # make sure the overlay2 storage driver is used by the DinD container.
86
+ # The VFS storage driver might get used if /var/lib/docker in the DinD container cannot be used by overlay2.
87
+ storage_driver=$( docker exec " ${dind_container} " docker info --format ' {{.Driver}}' )
88
+ if [[ " ${storage_driver} " != " overlay2" ]]; then
89
+ export remove_dind_container=" false"
90
+ echo " DinD container is not using overlay2 storage driver, storage driver detected: ${storage_driver} "
91
+ exit 1
92
+ fi
93
+
73
94
# remove the contents of /var/lib/docker-embedded so that any previous images are removed. Without this it seems to cause boot issues.
74
95
docker exec " ${dind_container} " sh -c " rm -rf /var/lib/docker-embedded/*"
75
96
@@ -97,7 +118,7 @@ function main() {
97
118
}
98
119
99
120
arch=" ${1-amd64} "
100
- dind_container_name=" hookos-dind- ${arch} "
121
+ dind_container_name=" hookos-dind"
101
122
images_file=" images.txt"
102
123
dind_container_image=" ${2-docker: dind} "
103
124
main " ${dind_container_name} " " ${images_file} " " ${arch} " " ${dind_container_image} "
0 commit comments