Skip to content

Commit c983023

Browse files
author
Solomon Hykes
committed
Copy dind wrapper script from github.com/jpetazzo/dind
1 parent eed00a4 commit c983023

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

hack/dind

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# First, make sure that cgroups are mounted correctly.
4+
CGROUP=/sys/fs/cgroup
5+
6+
[ -d $CGROUP ] ||
7+
mkdir $CGROUP
8+
9+
mountpoint -q $CGROUP ||
10+
mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
11+
echo "Could not make a tmpfs mount. Did you use -privileged?"
12+
exit 1
13+
}
14+
15+
# Mount the cgroup hierarchies exactly as they are in the parent system.
16+
for SUBSYS in $(cut -d: -f2 /proc/1/cgroup)
17+
do
18+
[ -d $CGROUP/$SUBSYS ] || mkdir $CGROUP/$SUBSYS
19+
mountpoint -q $CGROUP/$SUBSYS ||
20+
mount -n -t cgroup -o $SUBSYS cgroup $CGROUP/$SUBSYS
21+
done
22+
23+
# Note: as I write those lines, the LXC userland tools cannot setup
24+
# a "sub-container" properly if the "devices" cgroup is not in its
25+
# own hierarchy. Let's detect this and issue a warning.
26+
grep -q :devices: /proc/1/cgroup ||
27+
echo "WARNING: the 'devices' cgroup should be in its own hierarchy."
28+
grep -qw devices /proc/1/cgroup ||
29+
echo "WARNING: it looks like the 'devices' cgroup is not mounted."
30+
31+
# Now, close extraneous file descriptors.
32+
pushd /proc/self/fd
33+
for FD in *
34+
do
35+
case "$FD" in
36+
# Keep stdin/stdout/stderr
37+
[012])
38+
;;
39+
# Nuke everything else
40+
*)
41+
eval exec "$FD>&-"
42+
;;
43+
esac
44+
done
45+
popd
46+
47+
# If we were given a PORT environment variable, start as a simple daemon;
48+
# otherwise, spawn a shell as well
49+
if [ "$PORT" ]
50+
then
51+
exec docker -d -H 0.0.0.0:$PORT
52+
else
53+
54+
docker -d &
55+
exec bash
56+
fi

0 commit comments

Comments
 (0)