Browse code

Make get.docker.io install directions slightly better by telling user exactly how to add themselves to the "docker" group

As a bonus, if the user has run this script the way we recommend (ie, without "sudo" or "su", run as their user), we can actually give them the exact command they'll need with their correct username substituted appropriately.

Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)

Tianon Gravi authored on 2014/01/29 16:10:39
Showing 1 changed files
... ...
@@ -37,8 +37,10 @@ if command_exists docker || command_exists lxc-docker; then
37 37
 	( set -x; sleep 20 )
38 38
 fi
39 39
 
40
+user="$(id -un 2>/dev/null || true)"
41
+
40 42
 sh_c='sh -c'
41
-if [ "$(whoami 2>/dev/null || true)" != 'root' ]; then
43
+if [ "$user" != 'root' ]; then
42 44
 	if command_exists sudo; then
43 45
 		sh_c='sudo sh -c'
44 46
 	elif command_exists su; then
... ...
@@ -124,6 +126,16 @@ case "$lsb_dist" in
124 124
 				$sh_c 'docker run busybox echo "Docker has been successfully installed!"'
125 125
 			) || true
126 126
 		fi
127
+		your_user=your-user
128
+		[ "$user" != 'root' ] && your_user="$user"
129
+		echo
130
+		echo 'If you would like to use Docker as a non-root user, you should now consider'
131
+		echo 'adding your user to the "docker" group with something like:'
132
+		echo
133
+		echo '  sudo usermod -aG docker' $your_user
134
+		echo
135
+		echo 'Remember that you will have to log out and back in for this to take effect!'
136
+		echo
127 137
 		exit 0
128 138
 		;;
129 139