diff --git a/docker/gui/README.md b/docker/gui/README.md index 349ebed2..b819a321 100644 --- a/docker/gui/README.md +++ b/docker/gui/README.md @@ -39,9 +39,31 @@ $ mongod --smallfiles --config /etc/mongodb.conf +# Windows 支持 + +Windows 使用 [Xming](http://www.straightrunning.com/XmingNotes/) 作为 X11 服务器,安装配置网络连接之后启动 docker 容器。 + + + # OS X 支持 -// TODO +由于 OS X 没有自带 X11 服务器,需要手动安装后并配置允许网络客户端连接. + +* 安装 xquartz 作为 X11 服务器 + +~~~sh +$ brew cask install xquartz +~~~ + +* 打开 xquartz 并配置允许网络连接 + +![xquartz config](xquartz_preferences.png) + +* 执行脚本启动 docker + +~~~sh +$ ./run.sh +~~~ 参考博客 : [docker-for-mac-and-gui-applications](https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications/) diff --git a/docker/gui/run.sh b/docker/gui/run.sh index 2d893d1c..356a8367 100755 --- a/docker/gui/run.sh +++ b/docker/gui/run.sh @@ -4,10 +4,48 @@ THIS_DIR=$(cd `dirname $0`; pwd -P) TOPDIR=${THIS_DIR}/../.. id=vnpyuser - -display="-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY" +ostype=Linux +display= volume="-v ${TOPDIR}:/srv/vnpy" - -docker run -it --rm --name vnpy -u $id $display $volume vnpy /bin/bash +timezone="-e TZ=UTC-8" + + +function os_detect() { + osname=`uname -s` + case "${osname}" in + Linux*) ostype=Linux;; + Darwin*) ostype=Mac;; + CYGWIN*) ostype=Cywin;; + MINGW*) ostype=Mingw;; + *) ostype="Unknown-${osname}" + esac + echo "Your system is : ${ostype}" +} + +function osx_ip() { + ip=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}') + + if [ -z "$ip" ]; then + ip=$(ifconfig en1 | grep inet | awk '$1=="inet" {print $2}') + fi +} + +os_detect +if [ "${ostype}" = "Linux" ]; then + display="-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY" +elif [ "${ostype}" = "Mac" ]; then + osx_ip + display_number=`ps -ef | grep "Xquartz :\d" | grep -v xinit | awk '{ print $9; }'` + display="-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=${ip}${display_number}" + xhost + $ip +elif [ "${ostype}" = "Cywin" ]; then + +elif [ "${ostype}" = "Mingw" ]; then + +fi + +docker_args="-u $id $display $volume $timezone" + +docker run -it -d --name vnpy $docker_args vnpy /bin/bash diff --git a/docker/gui/xquartz_preferences.png b/docker/gui/xquartz_preferences.png new file mode 100644 index 00000000..4f8134a3 Binary files /dev/null and b/docker/gui/xquartz_preferences.png differ