<NME> run.sh
<BEF> #!/bin/sh

docker run --rm -p 6080:6080 thewtex/opengl
			;;
	esac
	shift
done


which docker 2>&1 >/dev/null
if [ $? -ne 0 ]; then
	echo "Error: the 'docker' command was not found.  Please install docker."
	exit 1
fi

os=$(uname)
if [ "${os}" != "Linux" ]; then
	vm=$(docker-machine active 2> /dev/null || echo "default")
	if ! docker-machine inspect "${vm}" &> /dev/null; then
		if [ -z "$quiet" ]; then
			echo "Creating machine ${vm}..."
		fi
		docker-machine -D create -d virtualbox --virtualbox-memory 2048 ${vm}
	fi
	docker-machine start ${vm} > /dev/null
    eval $(docker-machine env $vm --shell=sh)
fi

ip=$(docker-machine ip ${vm} 2> /dev/null || echo "localhost")
url="http://${ip}:$port"

cleanup() {
	docker stop $container >/dev/null
	docker rm $container >/dev/null
}

running=$(docker ps -a -q --filter "name=${container}")
if [ -n "$running" ]; then
	if [ -z "$quiet" ]; then
		echo "Stopping and removing the previous session..."
		echo ""
	fi
	cleanup
fi

if [ -z "$quiet" ]; then
	echo ""
	echo "Setting up the graphical application container..."
	echo ""
	if [ -n "$port" ]; then
		echo "Point your web browser to ${url}"
		echo ""
	fi
fi

pwd_dir="$(pwd)"
mount_local=""
if [ "${os}" = "Linux" ] || [ "${os}" = "Darwin" ]; then
	mount_local=" -v ${pwd_dir}:/home/user/work "
fi
port_arg=""
if [ -n "$port" ]; then
	port_arg="-p $port:6080"
fi

docker run \
  -d \
  --name $container \
  ${mount_local} \
  $port_arg \
  $extra_run_args \
  $image >/dev/null

print_app_output() {
	docker cp $container:/var/log/supervisor/graphical-app-launcher.log - \
		| tar xO
	result=$(docker cp $container:/tmp/graphical-app.return_code - \
		| tar xO)
	cleanup
	exit $result
}

trap "docker stop $container >/dev/null && print_app_output" SIGINT SIGTERM

docker wait $container >/dev/null

print_app_output

# vim: noexpandtab shiftwidth=4 tabstop=4 softtabstop=0

<MSG> Add advanced run.sh.

<DFF> @@ -1,3 +1,64 @@
 #!/bin/sh
 
-docker run --rm -p 6080:6080 thewtex/opengl
+# This script is a convenience script to run the container. It:
+#
+# - Makes sure docker is available
+# - On Windows and Mac OSX, creates a docker machine if required
+# - Informs the user of the URL to access the container with a web browser
+# - Stops and removes containers from previous runs to avoid conflicts
+# - Mounts the present working directory to /home/user/work on Linux and Mac OSX
+
+which docker &> /dev/null
+if [ $? -ne 0 ]; then
+	echo "Error: the 'docker' command was not found.  Please install docker."
+	exit 1
+fi
+
+_OS=$(uname)
+if [ "${_OS}" != "Linux" ]; then
+	_VM=$(docker-machine active 2> /dev/null || echo "default")
+	if ! docker-machine inspect "${_VM}" &> /dev/null; then
+		echo "Creating machine ${_VM}..."
+		docker-machine -D create -d virtualbox --virtualbox-memory 2048 ${_VM}
+	fi
+	docker-machine start ${_VM} > /dev/null
+    eval $(docker-machine env $_VM --shell=sh)
+fi
+
+_IP=$(docker-machine ip ${_VM} 2> /dev/null || echo "localhost")
+_URL="http://${_IP}:6080"
+
+_RUNNING=$(docker ps -q --filter "name=opengl")
+if [ -n "$_RUNNING" ]; then
+	echo "Stopping and removing the previous session..."
+	echo ""
+	docker stop opengl >/dev/null
+	docker rm opengl >/dev/null
+fi
+
+echo ""
+echo "Setting up the graphical application container..."
+echo ""
+echo "Point your web browser to ${_URL}"
+echo ""
+echo ""
+
+_PWD_DIR="$(pwd)"
+_MOUNT_LOCAL=""
+if [ "${_OS}" = "Linux" ] || [ "${_OS}" = "Darwin" ]; then
+	_MOUNT_LOCAL=" -v ${_PWD_DIR}:/home/user/work "
+fi
+docker run \
+  -d \
+  --name opengl \
+  ${_MOUNT_LOCAL} \
+  -p 6080:6080 \
+  thewtex/opengl &> /dev/null
+
+if [ "${_OS}" != "Linux" ] && [ "${_OS}" != "Darwin" ]; then
+	# Pause on Windows if the script was double-clicked instead of executed
+	# from the terminal so the URL can be read
+	read -p "Press any key to continue..." anykey
+fi
+
+# vim: noexpandtab shiftwidth=4 tabstop=4 softtabstop=0

Add advanced run.sh.