TDM 20200: Project 12 — 2024
Motivation: Containers are everywhere and a very popular method of packaging an application with all of the requisite dependencies. This project we will learn some basics of containerization in a virtual environment using Alpine Linux. We first will start a virtual machine on Anvil, then create a simple container in the virtual machine. You may find more information about container and relationship between virtual machine and container here: www.redhat.com/en/topics/containers/whats-a-linux-container
Context: The project is to provide very foundational knowledge about containers and virtualization, focusing on theoretical understanding and basic system interactions.
Scope: Python, containers, UNIX
Questions
Question 1 (2 pts)
-
Logon to Anvil and use a bash command to find an available port you may use later
Example code, you may modify or create your own code if needed
|
Question 2 (2 pts)
-
Launch a virtual machine (VM) on Anvil. (Note that Docker is already pre-installed on Anvil.) Submit the output showing the job id and process id, after you start a virtual machine; it should look like this, for example:
.output
[1] 3152048
The most popular containerization tool at the time of writing is likely Docker. We will Launch a virtual machine on Anvil (which already has Docker pre-installed). Open up a terminal on Anvil. You may do it from within Jupyter Lab. Run the following code, to ensure that the SLURM environment variables don’t alter or effect our SLURM job.
Next, let’s make a copy of a pre-made operating system image. This image has Alpine Linux and a few basic tools installed, including: nano, vim, emacs, and Docker.
Next, we need to make
Next, let’s launch our virtual machine with about 8GB of memory and 4 cores. Replace the "1025" with the port number that you got from question 1.
|
-
1025
is an example port number; this needs to be replaced with your port number!
Next, it is time to connect to our virtual machine. We will use ssh
to do this.
ssh -p 1025 tdm@localhost -o StrictHostKeyChecking=no
If the command fails, try waiting a minute and rerunning the command — it may take a minute for the virtual machine to boot up.
When prompted for a password, enter purdue
. Your username is tdm
and password is purdue
.
Finally, now that you have a shell in your virtual machine, you can do anything you want! You have superuser permissions within your virtual machine!
For this question, submit a screenshot showing the output of hostname
from within your virtual machine!
Question 3 (2 pts)
-
Use
df -h
to check the disk space. -
Use
printenv
to get the user’s environment variables. Choose 2 of those environment variables and explain their meanings. -
Use
ls
to list the files in the current directory-
You may refer to the following sample code (or create your own approach)
-
If
ls
does not return anything, usels -la
df -h printenv ls
-
Question 4 (2 pts)
-
Write and execute a shell script that calculates the number of files in the current directory and displays the result in a formatted message.
|
Question 5 (2 pts)
After you complete the previous questions, you can see that you can use the virtual machine just like your own computer. Now use the following steps, to use Docker within the virtual machine to create and manage a container. Run all the commands in your terminal. Copy the output to your Jupyter Lab cells.
-
List the docker version inside the virtual machine
docker --version
-
Pull the "ubuntu" image from Docker Hub
docker pull ubuntu
.Run a container based on the "ubuntu" imagedocker run -it ubuntu bash
When the command runs, docker will create a container from the
ubuntu
image and run it. -
Once inside the container shell, you should see the prompt changed to root@. Run the following command to install
cowsay
apt-get update && apt-get install -y cowsay
-
Now find the directory that
cowsay
locates. Go to that directory to runcowsay
with following command./cowsay "Your greetings here :)"
-
Use
exit
to leave the containerexit
-
List the container(s) with following command. It will provide you with a list of all of the containers that are currently running.
docker ps -a
-
After you confirm that the container ran successfully, you may using following command to remove it.
docker rm [Container_id]
Replace [Container_id] with the id that you got from previous question.
Project 12 Assignment Checklist
-
Jupyter Lab notebook with your code, comments and output for the assignment
-
firstname-lastname-project12.ipynb
-
-
bash file with code and comments for the assignment
-
firstname-lastname-project12.sh
-
-
Submit files through Gradescope
Please make sure to double check that your submission is complete, and contains all of your code and output before submitting. If you are on a spotty internet connection, it is recommended to download your submission after submitting it to make sure what you think you submitted, was what you actually submitted. In addition, please review our submission guidelines before submitting your project. |