Skip to content

Commit

Permalink
Merge pull request #62 from runzhammer/master
Browse files Browse the repository at this point in the history
add xvfb / notty support
  • Loading branch information
scottyhardy committed May 14, 2020
2 parents 9f60160 + 2d0923c commit d28b3cf
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ RUN apt-get update \
wget \
winbind \
zenity \
xvfb \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install wine
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ You can override the default interactive bash session by adding `wine`, `winetri

![Screenshot of Notepad](https://raw.githubusercontent.com/scottyhardy/docker-wine/master/images/screenshot_1.png)

## Run `docker-wine` with Xvfb

Starts up a frame buffer display defaulting to: Xvfb :95 -screen 0 320x200x8
Exports DISPLAY to the server number :95

```bash
./docker-wine --xvfb
```

### Customizable options

```bash
./docker-wine --xvfb=:95,0,320x200x8
```

## Run `docker-wine` attached with notty

```bash
./docker-wine --notty
```

## Run `docker-wine` with RDP server

Run with the `--rdp` option to start the RDP server with an interactive bash session:
Expand Down
58 changes: 48 additions & 10 deletions docker-wine
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ print_help () {
echo " --as-root Start the container as root"
echo " --as-me Start the container using your current username, UID and"
echo " GID (default when alternate --home value specified)"
echo " --notty Start container attached with no tty"
echo " --rdp Shortcut for --rdp=interactive"
echo " --rdp=OPTION Runs docker-wine container with Remote Desktop Protocol"
echo " server"
Expand All @@ -29,6 +30,13 @@ print_help () {
echo " interactive Start the RDP server and also run an"
echo " interactive bash session"
echo " --rdp-port=VALUE Bind RDP to a different TCP port (default is 3389)"
echo " --xvfb[=OPTIONAL] start xvfb"
echo " OPTIONAL consists of comma separated values of:"
echo " SERVER_NR Server number to use, eg. :1"
echo " SCREEN Screen number to use, eg. 0"
echo " RESOLUTION Screen resolution, eg. 320x240x8"
echo " if OPTIONAL is left blank, defaults to:"
echo " :95,0,320x240x8"
echo " --home-volume=VALUE Use an alternate volume to winehome for storing"
echo " persistent user data. Valid values can specify either"
echo " a docker volume or local path"
Expand Down Expand Up @@ -202,9 +210,6 @@ run_container () {
detached)
mode="--detach"
;;
-it|--detach)
mode="$1"
;;
*)
echo "ERROR: '${mode}' is not a valid container run mode"
exit 1
Expand Down Expand Up @@ -232,7 +237,14 @@ run_container () {
docker volume create winehome
fi

docker run "${mode}" "${RUN_ARGS[@]}" "${DOCKER_IMAGE}" "${CMD_ARGS[@]}"
# NOTTY rules them all
if [ "${NOTTY}" == "yes" ] ; then
#echo "docker run ${RUN_ARGS[@]} ${DOCKER_IMAGE} ${CMD_ARGS[@]}"
docker run "${RUN_ARGS[@]}" "${DOCKER_IMAGE}" "${CMD_ARGS[@]}"
else
#echo "docker run ${mode} ${RUN_ARGS[@]} ${DOCKER_IMAGE} ${CMD_ARGS[@]}"
docker run "${mode}" "${RUN_ARGS[@]}" "${DOCKER_IMAGE}" "${CMD_ARGS[@]}"
fi
}


Expand All @@ -244,6 +256,11 @@ DOCKER_PULL_IMAGE="yes"
IMAGE_TAG="latest"
USE_RDP_SERVER="no"
HOST_RDP_PORT="3389"
NOTTY="no"
XVFB="no"
XVFB_SERVER=":95"
XVFB_SCREEN="0"
XVFB_RESOLUTION="320x240x8"
USER_HOME="/home/wineuser"
USER_VOLUME="winehome"
WORKDIR="${USER_HOME}"
Expand Down Expand Up @@ -271,6 +288,9 @@ while [ $# -gt 0 ]; do
--as-me)
add_run_args_for_as_me
;;
--notty)
NOTTY="yes"
;;
--rdp)
USE_RDP_SERVER="interactive"
;;
Expand All @@ -280,6 +300,13 @@ while [ $# -gt 0 ]; do
--rdp-port=*)
HOST_RDP_PORT="${1#*=}"
;;
--xvfb)
XVFB="yes"
;;
--xvfb=*)
XVFB="yes"
IFS=, read XVFB_SERVER XVFB_SCREEN XVFB_RESOLUTION <<< "${1#*=}"
;;
--home-volume=*)
USER_VOLUME="${1#*=}"

Expand Down Expand Up @@ -403,7 +430,7 @@ else
elif [ "$(uname)" == "Linux" ]; then

# Check for .Xauthority which is required for authenticating as the current user on the host's X11 server
if [ -z "${XAUTHORITY:-${HOME}/.Xauthority}" ]; then
if [ -z "${XAUTHORITY:-${HOME}/.Xauthority}" -a "${XVFB}" == "no" ]; then
echo "ERROR: No valid .Xauthority file found for X11"
exit 1
fi
Expand Down Expand Up @@ -436,12 +463,23 @@ else
echo "INFO: pulseaudio not installed so running without sound"
fi

# Add Linux run args
add_run_arg --env="DISPLAY"
add_run_arg --volume="${XAUTHORITY:-${HOME}/.Xauthority}:/root/.Xauthority:ro"
add_run_arg --volume="/tmp/.X11-unix:/tmp/.X11-unix:ro"
# Run xvfb and send everything into the void
if [ "${XVFB}" == "yes" ] ; then
add_run_arg --env="XVFB=yes"
add_run_arg --env="XVFB_SERVER=${XVFB_SERVER}"
add_run_arg --env="XVFB_SCREEN=${XVFB_SCREEN}"
add_run_arg --env="XVFB_RESOLUTION=${XVFB_RESOLUTION}"
add_run_arg --env="DISPLAY=${XVFB_SERVER}"

run_container "interactive"
run_container "interactive"
else
# Add Linux run args
add_run_arg --env="DISPLAY"
add_run_arg --volume="${XAUTHORITY:-${HOME}/.Xauthority}:/root/.Xauthority:ro"
add_run_arg --volume="/tmp/.X11-unix:/tmp/.X11-unix:ro"

run_container "interactive"
fi
else
echo "ERROR: '$(uname)' OS is not supported"
exit 1
Expand Down
9 changes: 7 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@ fi
# Configure timezone
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime && echo "${TZ}" > /etc/timezone

# Run in X11 redirection mode (default)
# Run in X11 redirection mode (default) or with xvfb
if echo "${RDP_SERVER}" | grep -q -i -E "^(no|off|false|0)$"; then

# Set up pulseaudio for redirection to UNIX socket
[ -f /root/pulse/client.conf ] && cp /root/pulse/client.conf /etc/pulse/client.conf

# Run xvfb
if echo "${XVFB}" | grep -q -i -E "^(yes|on|true|1)$"; then
nohup /usr/bin/Xvfb ${XVFB_SERVER} -screen ${XVFB_SCREEN} ${XVFB_RESOLUTION} >/dev/null 2>&1 &
fi

# Run in X11 redirection mode as $USER_NAME (default)
if echo "${RUN_AS_ROOT}" | grep -q -i -E "^(no|off|false|0)$"; then

# Copy and take ownership of .Xauthority for X11 redirection
if [ -f /root/.Xauthority ]; then
if [ -f /root/.Xauthority -a "${XVFB}" == "no" ]; then
cp /root/.Xauthority "${USER_HOME}"
chown "${USER_UID}":"${USER_GID}" "${USER_HOME}/.Xauthority"
fi
Expand Down

0 comments on commit d28b3cf

Please sign in to comment.