Browse code

Copy dind wrapper script from github.com/jpetazzo/dind

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