@@ -54,6 +54,30 @@ if ! [ -d "$HOME" ]; then
54
54
exit 1
55
55
fi
56
56
57
+ mount_directory () {
58
+ if [ -z " $_DOCKERD_ROOTLESS_CHILD " ]; then
59
+ echo " mount_directory should be called from the child context. Otherwise data loss is at risk" >&2
60
+ exit 1
61
+ fi
62
+
63
+ DIRECTORY=" $1 "
64
+ if [ ! -d " $DIRECTORY " ]; then
65
+ return
66
+ fi
67
+
68
+ # Bind mount directory: this makes this directory visible to
69
+ # Dockerd, even if it is originally a symlink, given Dockerd does
70
+ # not always follow symlinks. Some directories might also be
71
+ # "copied-up", meaning that they will also be writable on the child
72
+ # namespace; this will be the case only if they are provided as
73
+ # --copy-up to the rootlesskit.
74
+ DIRECTORY_REALPATH=$( realpath " $DIRECTORY " )
75
+ MOUNT_OPTIONS=" ${2:- --bind} "
76
+ rm -rf " $DIRECTORY "
77
+ mkdir -p " $DIRECTORY "
78
+ mount $MOUNT_OPTIONS " $DIRECTORY_REALPATH " " $DIRECTORY "
79
+ }
80
+
57
81
rootlesskit=" "
58
82
for f in docker-rootlesskit rootlesskit; do
59
83
if command -v $f > /dev/null 2>&1 ; then
@@ -139,6 +163,25 @@ if [ -z "$_DOCKERD_ROOTLESS_CHILD" ]; then
139
163
" $0 " " $@ "
140
164
else
141
165
[ " $_DOCKERD_ROOTLESS_CHILD " = 1 ]
166
+
167
+ # The Container Device Interface (CDI) specs can be found by default
168
+ # under {/etc,/var/run}/cdi. More information at:
169
+ # https://github.com/cncf-tags/container-device-interface
170
+ #
171
+ # In order to use the Container Device Interface (CDI) integration,
172
+ # the CDI paths need to exist before the Docker daemon is started in
173
+ # order for it to read the CDI specification files. Otherwise, a
174
+ # Docker daemon restart will be required for the daemon to discover
175
+ # them.
176
+ #
177
+ # If another set of CDI paths (other than the default /etc/cdi and
178
+ # /var/run/cdi) are configured through the Docker configuration file
179
+ # (using "cdi-spec-dirs"), they need to be bind mounted in rootless
180
+ # mode; otherwise the Docker daemon won't have access to the CDI
181
+ # specification files.
182
+ mount_directory /etc/cdi
183
+ mount_directory /var/run/cdi
184
+
142
185
# remove the symlinks for the existing files in the parent namespace if any,
143
186
# so that we can create our own files in our mount namespace.
144
187
rm -f /run/docker /run/containerd /run/xtables.lock
@@ -153,10 +196,7 @@ else
153
196
if [ " $( stat -c %T -f /etc) " = " tmpfs" ] && [ -L " /etc/ssl" ]; then
154
197
# Workaround for "x509: certificate signed by unknown authority" on openSUSE Tumbleweed.
155
198
# https://github.com/rootless-containers/rootlesskit/issues/225
156
- realpath_etc_ssl=$( realpath /etc/ssl)
157
- rm -f /etc/ssl
158
- mkdir /etc/ssl
159
- mount --rbind ${realpath_etc_ssl} /etc/ssl
199
+ mount_directory /etc/ssl " --rbind"
160
200
fi
161
201
162
202
exec " $dockerd " " $@ "
0 commit comments