Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
Fix bugs in the entrypoint scripts.
  • Loading branch information
cainmagi committed Apr 14, 2022
1 parent ad6c603 commit 159f8d2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ git clone --single-branch -b xubuntu-minimal https://github.com/cainmagi/Dockerf
After that, run such command to build the image:

```Bash
docker build -t xminimal:1.0 xminimal
docker build -t xminimal:1 xminimal
```

where `xminimal` is the folder of the corresponding branch. The options in online building examples could be also used for offline building.
Expand All @@ -58,47 +58,59 @@ where `xminimal` is the folder of the corresponding branch. The options in onlin
* By built-in `noVNC`: In default mode, you just need to launch the built image by:

```bash
docker run --gpus all -it --rm -v ~:/homelocal -p 6080:6080 xminimal:1.0
docker run --gpus all -it --rm -v ~:/homelocal -p 6080:6080 xminimal:1.1
```

It is equivalent to use `--vnc` or not in the above command. However, if you have saved the image in other modes before, you may need this flag to force the image to enter the VNC mode. The `--vnc` option is required when you need to force the image to switch to VNC mode. The following command would force the `vnc` launched by `root` mode.

```bash
docker run --gpus all -it --rm -v ~:/homelocal -p 6080:6080 xminimal:1.0 --root
docker run --gpus all -it --rm -v ~:/homelocal -p 6080:6080 xminimal:1.1 --root
```

In current version, users could use either `http` to get access to the unencrypted noVNC session or `https` to get access to the ssl-encrypted noVNC session. For users who open the encrypted session firstly, they may need to add the noVNC site into the trusted list.

* Switch the VNCServer to `XTigerVNC` (experimental): Add the option `--xvnc` will make the desktop hosted by the `Xvnc` program. Everything will be run in the same process. There will be no sub-process manager like `tigervncserver` to manage desktop related programs. A good thing is that, users do not need to run `tigervncserver -kill :1` before saving the image. However, currently these desktop related programs are not guaranteed to be closed if hitting <kbd>Ctrl</kbd>+<kbd>C</kbd>. Therefore, we suggest the users to use `ps -aux` to validate the running processes before saving the image.

```bash
docker run --gpus all -it --rm -v ~:/homelocal -p 6080:6080 xminimal:1.1 --xvnc
```

Certainly, there is also a root mode for this method:

```bash
docker run --gpus all -it --rm -v ~:/homelocal -p 6080:6080 xminimal:1.1 --rootxvnc
```

* By external VNC viewer: If you have installed a VNC viewer on your client side, and want to connect the VNC server of the image directly, please use:

```bash
docker run --gpus all -it --rm -v ~:/homelocal -p 5901:5901 xminimal:1.0
docker run --gpus all -it --rm -v ~:/homelocal -p 5901:5901 xminimal:1.1
```

The `root` mode could be also applied here.

* By `BASH`: If you want to enter the command line but do not start the desktop, please use

```bash
docker run --gpus all -it --rm -v ~:/homelocal xminimal:1.0 --bash
docker run --gpus all -it --rm -v ~:/homelocal xminimal:1.1 --bash
```

* By any script: If you want run any script inside the docker for only one time, please use

```bash
docker run --gpus all -it --rm -v ~:/homelocal xminimal:1.0 script=<the-path-to-your-script>
docker run --gpus all -it --rm -v ~:/homelocal xminimal:1.1 script=<the-path-to-your-script>
```

* Switch the user id: When you use this image for the first time, please configure your user id by:

```bash
docker run --gpus all -it --rm -v ~:/homelocal xminimal:1.0 uid=$(id -u) gid=$(id -g)
docker run --gpus all -it --rm -v ~:/homelocal xminimal:1.1 uid=$(id -u) gid=$(id -g)
```

Then commit the image by

```bash
docker commit --change='CMD [""]' <conatiner-id> xminimal:1.0
docker commit --change='CMD [""]' <conatiner-id> xminimal:1.1
```

## Features
Expand Down
12 changes: 6 additions & 6 deletions entrypoints/docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ then
echo "Find VNC password."
else
sudo tigervncpasswd ${FILE_VNCPASSWD}
mkdir -p /home/xubuntu/.vnc/ || fail
if $(sudo [ ! -s /home/xubuntu/.vnc/passwd ]); then
sudo cp -f ${FILE_VNCPASSWD} /home/xubuntu/.vnc/ || fail
sudo chown xubuntu /home/xubuntu/.vnc/passwd || fail
sudo chgrp xubuntu /home/xubuntu/.vnc/passwd || fail
sudo chmod ug+rwx /home/xubuntu/.vnc/passwd || fail
mkdir -p ${USER_ROOT}/.vnc/ || fail
if $(sudo [ ! -s ${USER_ROOT}/.vnc/passwd ]); then
sudo cp -f ${FILE_VNCPASSWD} ${USER_ROOT}/.vnc/ || fail
sudo chown xubuntu ${USER_ROOT}/.vnc/passwd || fail
sudo chgrp xubuntu ${USER_ROOT}/.vnc/passwd || fail
sudo chmod ug+rwx ${USER_ROOT}/.vnc/passwd || fail
fi
fi
else
Expand Down
38 changes: 19 additions & 19 deletions entrypoints/xvnc-launch
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ function mcd {
cd "$1" || fail
}

kill_descendant_processes() {
local pid="$1"
local and_self="${2:-false}"
if children="$(pgrep -P "$pid")"; then
for child in $children; do
kill_descendant_processes "$child" true
done
fi
if [[ "$and_self" == true ]]; then
kill -9 "$pid"
fi
}

MODE="xvnc"
USER_ROOT="/home/xubuntu"
# Pass options from command line
Expand Down Expand Up @@ -68,12 +55,12 @@ then
echo "Find VNC password."
else
sudo tigervncpasswd ${FILE_VNCPASSWD}
mkdir -p /home/xubuntu/.vnc/ || fail
if $(sudo [ ! -s /home/xubuntu/.vnc/passwd ]); then
sudo cp -f ${FILE_VNCPASSWD} /home/xubuntu/.vnc/ || fail
sudo chown xubuntu /home/xubuntu/.vnc/passwd || fail
sudo chgrp xubuntu /home/xubuntu/.vnc/passwd || fail
sudo chmod ug+rwx /home/xubuntu/.vnc/passwd || fail
mkdir -p ${USER_ROOT}/.vnc/ || fail
if $(sudo [ ! -s ${USER_ROOT}/.vnc/passwd ]); then
sudo cp -f ${FILE_VNCPASSWD} ${USER_ROOT}/.vnc/ || fail
sudo chown xubuntu ${USER_ROOT}/.vnc/passwd || fail
sudo chgrp xubuntu ${USER_ROOT}/.vnc/passwd || fail
sudo chmod ug+rwx ${USER_ROOT}/.vnc/passwd || fail
fi
fi
else
Expand Down Expand Up @@ -129,6 +116,19 @@ exec noVNC --cert /apps/source/noVNC/utils/websockify/self.pem --key /apps/sourc
msg "Wait CTRL+C from users."
( trap exit SIGINT ; read -r -d '' _ </dev/tty ) # wait for Ctrl-C

kill_descendant_processes() {
local pid="$1"
local and_self="${2:-false}"
if children="$(pgrep -P "$pid")"; then
for child in $children; do
kill_descendant_processes "$child" true
done
fi
if [[ "$and_self" == true ]]; then
kill -9 "$pid" || true
fi
}

kill_descendant_processes $$

exit 0

0 comments on commit 159f8d2

Please sign in to comment.