Skip sudo if there is a writable docker socket
Make it possible to use hack/dind-cluster.sh without sudo if the docker socket is writable by the current user.
@@ -525,7 +525,21 @@ function build-image() {
popd > /dev/null
}
-DOCKER_CMD=${DOCKER_CMD:-"sudo docker"}
+
+## Start of the main program
+
+DEFAULT_DOCKER_CMD="sudo docker"
+if [[ -w "/var/run/docker.sock" ]]; then
+ DEFAULT_DOCKER_CMD="docker"
+
+ # Since docker is a shell script we do not want to pass our restrictions to it
+ # This would be stripped by sudo, but we have to do it manually otherwise
+ export -n SHELLOPTS
+else
+ # Make sure that they don't do half the work if sudo fails later by getting it primed now
+ sudo echo -n
+fi
+DOCKER_CMD="${DOCKER_CMD:-$DEFAULT_DOCKER_CMD}"
CLUSTER_ID="${OPENSHIFT_CLUSTER_ID:-openshift}"
