What is a Docker container and image?
Container
According to Docker’s website:
A container is a sandboxed process running on a host machine that is isolated from all other processes running on that host machine. That isolation leverages kernel namespaces and cgroups, features that have been in Linux for a long time. Docker makes these capabilities approachable and easy to use. To summarize, a container:
- Is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI.
- Can be run on local machines, virtual machines, or deployed to the cloud.
- Is portable (and can be run on any OS).
- Is isolated from other containers and runs its own software, binaries, configurations, etc.
Image
According to Docker’s website:
A running container uses an isolated filesystem. This isolated filesystem is provided by an image, and the image must contain everything needed to run an application - all dependencies, configurations, scripts, binaries, etc. The image also contains other configurations for the container, such as environment variables, a default command to run, and other metadata.
References
https://docs.docker.com/get-started/
Creating a new Docker image for Kasm
NOTE: Kasm offers advice on how to properly create containers that will run on its streaming platform with little to no hiccups. This is because Kasm generally uses its own version of Ubuntu 20.0.4 (Focal Fossa)
operating system.
The modified Ubuntu OS is meant to be lightweight and comes preloaded with the necessary configurations and packages for Docker containers to operate and stream.
Build a Basic Container for Testing
NOTE: Before going on to build a custom container image, it’s best to test out a basic image and make it work on Kasm before doing anything more complicated.
- On the Debian 12 VM, Create a directory in the home folder called “Docker” and change into that directory.
mkdir ~/Docker && cd ~/Docker
- Create another directory called “Test” and change into that directory.
mkdir Test && cd Test
- The current working directory will be
~/Docker/Test
- The current working directory will be
- Using a text editor, create a file named
Dockerfile
:vim Dockerfile
- Copy and paste the following information into the file:
# Specify the kasm version of Ubuntu to pull FROM kasmweb/core-ubuntu-focal:1.14.0 # Use the root user for the following tasks USER root # Create new variables to specify locations ENV HOME /home/kasm-default-profile ENV STARTUPDIR /dockerstartup ENV INST_SCRIPTS $STARTUPDIR/install # Make the working directory the home folder WORKDIR $HOME ######### Customize Container Here ########### # Once the Kasm version of Ubuntu is loaded, run any code that needs to execute to create the environment. # A simple test of creating a "hello.txt" file on the desktop will do. RUN touch $HOME/Desktop/hello.txt ######### End Customizations ########### # Change ownership of the home folder to user 1000 (kasm-user) RUN chown 1000:0 $HOME RUN $STARTUPDIR/set_user_permission.sh $HOME # Change the $HOME variable to user 1000 (kasm-user) ENV HOME /home/kasm-user # Make the working directory the home folder for user 1000 (kasm-user) WORKDIR $HOME # Make the new home directory and change ownership to user 1000 (kasm-user) RUN mkdir -p $HOME && chown -R 1000:0 $HOME # Change to user 1000 (kasm-user) USER 1000
- Save the file.
- This file is a “blueprint” for Docker to build an image file. Build the new image:
sudo docker build -t dockerfile-test:latest -f Dockerfile .
- Verify the image has been created by listing all current Docker images:
sudo docker image ls
- Open Kasm Web GUI and login to the “Admin” account.
- In the left pane, expand “Workspaces”, click “Workspaces”
- Click “Add Workspace”
- Fill out all of the required information on the form. Use the following criteria:
Workspace Type: Container Friendly Name: Dockerfile Test Description: Test of our simple Dockerfile Enabled: Yes Docker Image: dockerfile-test:latest Cores: 2 Memory: 2048 GPU Count: 0 CPU Allocation Method: Inherit
- Save the changes.
- At the top of the web page, click “Workspaces”
- The “Dockerfile Test” workspace should be there.
- Select it and then launch the workspace in the current tab.
- Verify that a desktop environment loads with a text file called “hello.txt”
- Once verified, delete the session from the control panel on the left side of the window.
Creating a Custom Container
Choosing an application to run
Knowing that the basic container image built and ran, a custom container can now be designed. However, any other application can be “containerized” for this purpose.
A popular application and game known as “DooM” would be a perfect and fun experiment to turn into a container for Docker to run. However, Kasm has already done this with a freeware version of DooM, but some custom versions of DooM exist that would be even more exciting to try out in a container. Namely, “psDooM” that is a modification for DooM that ties enemies into actually running processes.
It is an ingenious idea but getting it to function in a Kasm specific Docker container will take some elbow grease.
Also, there are many people associated with the development of psDooM and the platform it uses called “Chocolate Doom”. To find out more information about the game, here is a link for reading: https://github.com/orsonteodoro/psdoom-ng/tree/master
Creating a Custom Docker Image for psDooM
- On the Debian 12 VM, In the
~/Docker
directory that was created earlier, create another folder calledpsdoom-kasm
and change into that directory:mkdir ~/Docker/psdoom-kasm && cd ~/Docker/psdoom-kasm
- Using a text editor, create a file called
psdoom-kasm-image
:vim psdoom-kasm-image
- This will be the Dockerfile that will be used to build the image. Copy and paste the following information into the file:
# Use the Kasm modified Ubuntu image as a base. FROM kasmweb/core-ubuntu-focal:1.14.0 # Do all of the following as the root user. USER root # Create environment variables. ENV HOME /home/kasm-default-profile ENV STARTUPDIR /dockerstartup ENV INST_SCRIPTS $STARTUPDIR/install ENV PSDOOM_LOG /tmp/psdoom_install_log.txt ENV DOOM_WAD /usr/share/games/doom # The working directory will be the home folder. WORKDIR $HOME ######### Customize Container Here ########### # Create the PSDOOM Log file RUN touch $PSDOOM_LOG # Clone the working version of psDooM 1.6.0 RUN git clone --depth 1 --branch 1.6.0 https://github.com/orsonteodoro/psdoom-ng.git \ && echo "GIT CLONE SUCCESSFUL" >> $PSDOOM_LOG # Install dependencies and developer tools. RUN apt update \ && apt install -y make \ && apt install -y gcc \ && apt install -y libsdl-mixer1.2 \ && apt install -y libsdl-mixer1.2-dev \ && apt install -y libsdl-net1.2 \ && apt install -y libsdl-net1.2-dev \ && apt install -y libsdl1.2debian \ && apt install -y libsdl1.2-dev \ && apt install -y libsdl-sound1.2 \ && apt install -y libsdl-sound1.2-dev \ && echo "DEPENDENCIES INSTALLED SUCCESSFULLY" >> $PSDOOM_LOG \ && apt install -y autotools-dev \ && apt install -y autoconf \ && echo "TOOLS INSTALLED SUCCESSFULLY" >> $PSDOOM_LOG # Change working directory to the cloned directory and install psDooM. After install, create directory for WAD files. RUN cd ~/psdoom-ng/trunk \ && ./configure \ && make \ && make install \ && mkdir -p $DOOM_WAD \ && echo "DOOM INSTALLED SUCCESSFULLY" >> $PSDOOM_LOG # Copy the IWAD and Custom map WAD files from the local machine to the container COPY wad/doom2.wad $DOOM_WAD COPY wad/psdoom2.wad $DOOM_WAD # Copy the custom startup script for the game to launch properly COPY scripts/custom_startup.sh $STARTUPDIR/custom_startup.sh RUN chmod 755 $STARTUPDIR/custom_startup.sh # Update the desktop environment to be optimized for a single application RUN cp $HOME/.config/xfce4/xfconf/single-application-xfce-perchannel-xml/* $HOME/.config/xfce4/xfconf/xfce-perchannel-xml/ && cp /usr/share/extra/backgrounds/bg_kasm.png /usr/share/extra/backgrounds/bg_default.png && apt-get remove -y xfce4-panel ######### End Customizations ###########
- The container will not be built with Docker just yet because there are a few prerequisite tasks that must be completed.
Game Files
Acquire a copy of Doom 2
In order to run the psDooM game, there must be a legitimate copy of DooM 2 present on the system, otherwise obtaining the game by copying files from someplace else could result in prosecution by the law as the original DooM games are copyrighted material.
The game can be purchased in many ways, but the easiest way is to buy a copy from Steam: https://store.steampowered.com/app/2300/DOOM_II/
NOTE: The game may need to be installed on a Windows client.
Retrieve WAD Files
DooM games use a “WAD” file that contains the necessary data to run the game. Ultimately, “psDooM” is just a modification of DooM, so that’s why the WAD files are needed.
- Once DooM 2 is installed on the local Windows client computer, go into the directory where the game is installed.
- Look for a file name called
doom2.wad
and copy it somewhere where it can be found easily. - Download this file from the “psDooM” Git repo: https://github.com/orsonteodoro/psdoom-ng/blob/8a27458baf3d098df7436281b5a2ed80f9007ccf/extras/psdoom-2000.05.03-data.tar.gz
- This file contains a custom map that will be needed for the psDooM mod.
- Once downloaded, extract the tarball and find the
psdoom2.wad
file, and save it to the same place where the otherdoom2.wad
file is located. - Both the
doom2.wad
andpsdoom2.wad
files will be used for the next steps.
Copy the WAD files
- On the Debian 12 VM, In the same directory as the
psdoom-kasm-image
Dockerfile that was create earlier, create another directory called “wad”:mkdir ~/Docker/wad/
- Using any method, copy both the
doom2.wad
andpsdoom2.wad
files from the local Windows client machine into thewad/
directory on the Debian 12 VM.- One method could be to use secure copy or
scp
to copy them to the Proxmox server, and then to the Debian 12 VM. - Another method could be uploading them to a website, and then using
curl
to download them onto the Debian 12 VM.
- One method could be to use secure copy or
Create a Kasm Custom Startup Script
NOTE: Every image that Kasm uses to start containers can contain a custom_startup.sh
script that will be automatically called when the container starts up. This script is mainly used to clean up the desktop environment, start up the desired program, and log anything that is necessary.
- On the Debian 12 VM, in the same directory as the
psdoom-kasm-image
Dockerfile, create another directory called “scripts” and change into that directory:mkdir ~/Docker/scripts && cd ~/Docker/scripts
- Create a custom bash script called
custom_startup.sh
:vim custom_startup.sh
- Copy and paste the following information into the file:
#!/usr/bin/env bash # Create a log file to monitor the execution of this script. $CUSTOMLOG = "/tmp/custom_startup.log" touch $CUSTOMLOG # Run the desktop_ready Kasm script to before executing main program. /usr/bin/desktop_ready echo "desktop_ready command ran" >> $CUSTOMLOG # Assign the start command for psDooM to the "START_COMMAND" variable. START_COMMAND="/home/kasm-default-profile/psdoom-ng/trunk/src/psdoom -iwad /usr/share/games/doom/doom2.wad -file /usr/share/games/doom/psdoom2.wad -psuser root -nomonsters -window" echo "START_COMMAND variable assigned" >> $CUSTOMLOG # Start psDooM. $START_COMMAND & echo "Starting psDooM with START_COMMAND variable" >> $CUSTOMLOG # Maximize the psDooM (Chocolate Doom) Window (NOTE: It will only run at a specific resolution until fixed). # echo "wmctrl executing..." >> $CUSTOMLOG # wmctrl -r "DOOM 2: Hell on Earth - psdoom 2012.02.05-1.6.0" -b add,maximized_vert,maximized_horz -v &> /tmp/custom_startup.log # echo "wmctrl executed." >> $CUSTOMLOG
- Save the file.
- Built the image with Docker:
sudo docker build -t psdoom-kasm:1.0 -f psdoom-kasm-image .
- Verify the image has been created by listing all current Docker images:
sudo docker image ls
- Open Kasm Web GUI and login to the “Admin” account.
- In the left pane, expand “Workspaces”, click “Workspaces”
- Click “Add Workspace”
- Fill out all of the required information on the form. Use the following criteria:
Workspace Type: Container Friendly Name: psDooM Description: psDooM Version 1.6.0 Enabled: Yes Docker Image: psdoom-kasm:1.0 Cores: 2 Memory: 4096 GPU Count: 0 CPU Allocation Method: Inherit Docker Run Config Override (JSON): {"user":"root"}
- Save the changes.
- At the top of the web page, click “Workspaces”
- The “Dockerfile Test” workspace should be there.
- Select it and then launch the workspace in the current tab.
- Verify that psDooM loads up.
- Once verified, delete the session from the control panel on the left side of the window.
References
https://kasmweb.com/docs/latest/how_to/building_images.html https://devopscube.com/build-docker-image/ https://github.com/kasmtech/workspaces-images/blob/develop/src/ubuntu/install/doom/install_doom.sh https://github.com/kasmtech/workspaces-images/blob/develop/dockerfile-kasm-doom
Upload the image to Docker Hub
NOTE: Storing the image locally is nice, but what if something ever happened to the storage on the server? It is a good idea to back up the image to a cloud service such as Docker Hub. Create a Docker Hub account by visiting: https://hub.docker.com/
Docker Hub is a remote repository for Docker images, similar to how GitHub is a remote repository for code.
Keep in mind that copyrighted game files are now within the Docker image, and it is important to not release the Docker image to the public. To do this, a private Docker repository must be made where the Docker image is uploaded to.
Create a private repository
NOTE: Use the local Windows client machine to perform the following steps.
- Login to Docker Hub (create an account if necessary).
- Click “Create Repository”
- Make the repository name “psdoom-kasm”
- In the description, enter “psDooM version 1.6.0 for Kasm”
- Change the visibility to “Private”
- Click “Create”
Create an Access Token
NOTE: An access token is like a password, but temporary. It is used to authenticate into a Docker Hub account, but will be deleted after a certain amount of time or uses.
- On the Docker Hub website, go to “Account Settings”
- Navigate to “Security”
- Create a “New Access Token”
- Access token description can be “psdoom”
- Make sure it has “Read, Write, Delete” permissions.
- Copy the access token to a safe place (i.e. an encrypted file on the local desktop computer).
Log into Docker on through the Debian 12 command line
- On the Debian 12 VM command line, log into Docker Hub:
docker login -u <username>
- Enter the token as the password.
- It should say “Login Succeeded”.
- Never share the token and always make sure to disable it or delete it on Docker Hub once it is no longer needed.
Pushing the Docker image
- Tag the image for the private repository:
sudo docker tag psdoom-kasm:1.0 <username>/psdoom-kasm:1.0
- Push the image to the private repository:
sudo docker push <username>/psdoom-kasm:1.0
Configure Kasm to use Docker Hub image
NOTE: Kasm can either use local storage, Docker Hub storage, or even third-party registry’s for image storage.
- Open up the Kasm Web GUI and login as “Admin”.
- At the top of the web page, click “Admin”
- On the left pane, expand “Workspaces”, then click “Workspaces”
- Click “Add Workspace”
- Fill out the form with the following criteria:
Workspace Type: Container Friendly Name: psDooM Description: psDooM Version 1.6.0 Enabled: Yes Docker Image: <DockerHub_username>/psdoom-kasm:1.0 Cores: 2 Memory: 4096 GPU Count: 0 CPU Allocation Method: Inherit Docker Registry: https://index.docker.io/v1/ Docker Registry Username: <DockerHub_username> Docker Registry Password: <DockerHub_token> Docker Run Config Override (JSON): {"user":"root"}
- Save the changes.
- The image will take time to download.
- View the installation progress by navigating to “Registry” and then selecting “Installed Workspaces”.
- This process could take up to 20 minutes (depending on internet connection and storage speed).
- Once it is installed, navigate to “Workspaces” at the top of the screen.
- Launch the “psDooM” workspace in the current tab.
- Verify it works.
- Once verified, delete the session from the control panel on the left side of the window.