Docker Sandbox Script – Now with VNC!

Thought I might post a follow-up to my previous post.

As mentioned they lock our computers down at my new company, so I needed a way to test code in a unrestricted environment.

Today, I took it a step further with the addition of a GUI utilizing a VNC Server.

As a bonus I even managed to get RuneScape running on it and it runs suprisingly well, no skips/lag/delay of any kind!

eGLIn5j.png

Below is the source if you’d like to try it out.

@echo off

SET DOCKER="docker"

SET CONTAINER_NAME="linuxSandbox"
SET IMAGE_TO_USE="centos:latest"
SET IMAGE_TO_USE_SANDBOX="sandbox:%CONTAINER_NAME%"

echo Container - %CONTAINER_NAME%
echo Select an Option to Continue:
echo [0] - Container - Create
echo [1] - Container - Start
echo [2] - Container - Stop
echo [3] - Container - Terminal
echo [4] - Container - Destroy

set /p CHOICE="Enter Selection: "

IF "%CHOICE%" == "0" (
%DOCKER% pull "%IMAGE_TO_USE%"

start /MIN "" "%DOCKER%" run -it --privileged --name %CONTAINER_NAME% %IMAGE_TO_USE% bash

timeout 10

%DOCKER% exec -it %CONTAINER_NAME% bash -c "yum -y update;yum clean all"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "yum -y install openssh-server passwd; yum clean all"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "mkdir /var/run/sshd"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "echo 'root:password' | chpasswd"

%DOCKER% exec -it %CONTAINER_NAME% bash -c "yum -y install epel-release"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "yum groupinstall \"Xfce\" -y"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "yum -y install tigervnc-server tigervnc-server-minimal"

%DOCKER% exec -it %CONTAINER_NAME% bash -c "yum -y install file-roller"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "yum -y install java"

%DOCKER% exec -it %CONTAINER_NAME% bash -c "dbus-uuidgen > /var/lib/dbus/machine-id"

%DOCKER% exec -it %CONTAINER_NAME% bash -c "printf \"password\npassword\n\n\" | vncpasswd"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "vncserver -rfbport 5902 "
%DOCKER% exec -it %CONTAINER_NAME% bash -c "vncserver -kill :1"
rem %DOCKER% exec -it %CONTAINER_NAME% bash -c "mv ~/.vnc/xstartup ~/.vnc/xstartup.bekup"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "echo '#!/bin/bash' > ~/.vnc/xstartup"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "echo 'xrdb $HOME/.Xresources' >> ~/.vnc/xstartup"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "echo 'startxfce4 &' >> ~/.vnc/xstartup"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "chmod +x ~/.vnc/xstartup"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "cp /etc/X11/Xresources ~/.Xresources"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "vncserver -rfbport 5902"

%DOCKER% exec -it %CONTAINER_NAME% bash -c "echo 'nohup vncserver -rfbport 5902 &' > /startup.sh"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "echo '/usr/sbin/sshd -D &' >> /startup.sh"
%DOCKER% exec -it %CONTAINER_NAME% bash -c "echo 'ping localhost' >> /startup.sh"
%DOCKER% commit %CONTAINER_NAME% %IMAGE_TO_USE_SANDBOX%
%DOCKER% stop %CONTAINER_NAME%
%DOCKER% rm %CONTAINER_NAME%

%DOCKER% run -d --privileged --name %CONTAINER_NAME% -p "22:22" -p "5902:5902" %IMAGE_TO_USE_SANDBOX% sh /startup.sh
)

IF "%CHOICE%" == "1" (
%DOCKER% start %CONTAINER_NAME%
)

IF "%CHOICE%" == "2" (
%DOCKER% stop %CONTAINER_NAME%
)

IF "%CHOICE%" == "3" (
%DOCKER% exec -it %CONTAINER_NAME% bash
)

IF "%CHOICE%" == "4" (
%DOCKER% stop %CONTAINER_NAME%
%DOCKER% rm %CONTAINER_NAME%
%DOCKER% rmi %IMAGE_TO_USE_SANDBOX%
)

pause

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s