0% found this document useful (0 votes)
24 views

Lab 0 - (Part 1) Lab Environment Setup

Uploaded by

mir.inzamam200
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lab 0 - (Part 1) Lab Environment Setup

Uploaded by

mir.inzamam200
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Course & Instructor Info

Course Name: CSE 4650 - Systems Programming Lab


Instructor: Imtiaj Ahmed Chowdhury, Lecturer, CSE, IUT
Lab Courtesy: CS300 - Fundamentals of Computer Systems (Brown University), adapted under CC BY
4.0

Lab 0 - Part 1
Setting up the lab environment
Welcome to the first lab! The main focus will be to get you set up with the tools we’ll be using throughout all
the labs, and give you an intuitive understanding of each one.

The main tools we’ll be using are Docker, a convenient way to manage virtual environments as “containers”,
and Git, the most prominent version control software.

1 | Tool | Use |
|------------|--------------------------------------------|
2
| Docker | Software environment virtualization |
3
| Git | Version control software |
4 | GitHub | Online code storage and version control|
5

Why are we using these tools?


You’ll be able to develop locally. With virtualization, we can specify a standard development
environment on any machine, so your code will work no matter where it’s run.
Version control is awesome. All changes to your code are tracked and can be reverted, making testing
and debugging significantly more bearable. Your changes are also semi-automatically merged with other
people’s, making collaboration easy.
It’s how it’s done in the industry. Most companies use some form of version-control in order to better
manage projects and collaboration, and use machine virtualization for easier deployment and testing.

Install and Setup Linux


For this lab, it is recommended to install and setup Ubuntu as a virtual machine in your main OS. A Virtual
Machine (VM) can establish the same software environment for everyone. Software inside a VM believes it is
running on a physical computer, even though it is running within an OS within another computer. Achieving
this level of virtualization has costs, including the cost of emulating the underlying hardware.
Follow this tutorial for setting up VirtualBox, an open-source virtualiser software, and install Ubuntu image on
it. All the following installations in this handout must be done in this installed Ubuntu VM.

Docker
Docker is one of the most popular container solutions and widely used in industry. Follow the instructions
here to install Docker in your Ubuntu. It is recommended to follow the installation method using apt repository.
Verify Docker is installed by executing the following command in a terminal:
$ docker --version

A Docker version number should be printed.


After installing Docker, a Docker process (the Docker daemon) will run in the background. Run the following
command to verify:

$ docker info

This should print some information about your Docker installation.


If you see the following error:

ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon
running?

it means Docker hasn’t started running yet. On Linux, try the command sudo systemctl docker restart in a
terminal.

Set up lab docker environment


In Docker, an environment is defined as a Docker image. An image specifies the operating system
environment that a container provides. An image can also contain additional software dependencies and
configurations. These instructions are specified in a file, the so-called Dockerfile.
Next, you will download the the lab’s setup code and create the lab Docker image! This docker image is part
of the course CS 300 from Brown University. In all of your labs, the container built from this image will be
used.

Task

Do the following to set up your development environment.

1. Enter the directory on your computer where you want to do your coursework.
Then, enter the following command to download the development environment to the new
subdirectory DEV-ENVIRONMENT (you can choose your own name, DEV-ENVIRONMENT is a placeholder!):

$ git clone https://github.com/csci0300/cs300-s23-devenv.git DEV-ENVIRONMENT

This command clones a GitHub repository onto your computer; we will explain the details of Git and cloning
later in the lab.
2. Run cd DEV-ENVIRONMENT to enter the directory you have just created.
3. Inside this folder, do the following:

$ cd docker # enters the folder containing Dockerfiles


$ ./cs300-build-docker # builds a docker image you'll use in the semester

./cs300-build-docker builds your docker image, which may take a while. It’s normal for this script to run for
around 20-30 minutes.

Why are there two Dockerfiles?


You may notice that there are two Dockerfiles in the docker folder: Dockerfile and Dockerfile.arm64 . Why
are there two Dockerfiles, when the lab only uses one container?
Machines run on different architectures, and we will explore that in our course during the semester.
Computers that use an Intel chip runs on Intel’s x86 architecture. Recent Macs released by Apple begin to
use Apple silicon, which run on the ARM architecture.
Different architectures use different sets of CPU instructions. Therefore, programs running on different
architectures need to be compiled differently.
Some lab assignments are designed to run on the x86 architecture. When running these projects on a
different architecture (e.g., on an Apple M1 machine), they must be cross-compiled to use x86 instructions.
Students running on ARM machines use DockerFile.arm64 , which installs additional packages to compile x86
binaries on an ARM machine. Other students, running on chips that use the x86 architecture,
use Dockerfile .

Entering the container


Once you created your Docker image, you will want to create a container running this image. To understand
the difference between a Docker image and a container, you can read this excellent blog post.

Task

Enter your container and explore it by running a few commands. Then, exit the container by exit , or Ctrl-D.
Make sure you’re inside directory DEV-ENVIRONMENT when running the command below.

$ ./cs300-run-docker # enters your Docker container


cs300-user@9899143429a2:~$ # you're inside the container!
cs300-user@9899143429a2:~$ uname
Linux
cs300-user@9899143429a2:~$ echo "Hello world!"
Hello world!
cs300-user@9899143429a2:~$ ls -lah
total 24K
drwxr-xr-x 6 cs300-user cs300-user 192 Jan 25 22:23 .
drwxr-xr-x 1 root root 4.0K Jan 25 22:25 ..
-rw-r--r-- 1 cs300-user cs300-user 132 Jan 25 22:23 .bash_profile
-rw-r--r-- 1 cs300-user cs300-user 4.0K Jan 25 22:23 .bashrc
-rw-r--r-- 1 cs300-user cs300-user 25 Jan 25 22:23 .gdbinit
-rw-r--r-- 1 cs300-user cs300-user 813 Jan 25 22:23 .profile
cs300-user@9899143429a2:~$ exit # or Ctrl-D

Don’t worry if the number after cs300-user is different. This is an identifier that uniquely identifies this
container.
You may run any Linux commands inside this container. To exit, enter exit or use Ctrl-D.

Shared Folders
“If my docker container is a separate (virtual) computer than my laptop, how will I move files between the
two?”, you may ask. Great question! You’ll move files between the two in any of the ways you can move files
between any two computers! (Bear with us!)
To get files to and from department machines, you may have used things like scp , sftp , and Cyberduck,
which allow you to copy files over the network. These work, but are inconvenient if you’re constantly moving
them back and forth. (Git would technically also fall under this category, even though it’s fancier, as you’ll find
out shortly.)
If you’re lucky, you may have been exposed to FUSE and sshfs , which allow you to mount a filesystem over
the network. This allows your computer to navigate the remote files as if they were stored locally, which
means any changes you make are happening on both ends automatically.
Inside of the container, your home directory ( /home/cs300-user , or ~ ) is actually a mount of
the home directory inside your DEV-ENVIRONMENT directory. Any changes you make in one will be visible in the
other.

Task

Outside of the container, go into your [DEV-ENVIRONMENT]/home folder, and create a file and a folder. Then, go
into your container, delete that file, and add a file to the folder. This is so you get a feel for what is going on,
since you’ll be using this on a regular basis!

Step-by-step guide

Outside of the container, in your [DEV-ENVIRONMENT]/home folder:

$ touch cool_file
$ mkdir awesome_folder
$ cd ..
$ ./cs300-run-docker

Inside the container:

cs300-user@9899143429a2:~$ ls # print the file and dir we just created


awesome_folder cool_file

cs300-user@9899143429a2:~$ rm cool_file
cs300-user@9899143429a2:~$ cd awesome_folder
cs300-user@9899143429a2:~$ touch even_cooler_file
cs300-user@9899143429a2:~$ exit # or just CTRL-D

Back outside the container:

$ cd home # this enters the mounted directory


$ ls # should just show awesome_folder
awesome_folder
$ cd awesome_folder
$ ls # should show even_cooler_file
even_cooler_file

If you move or rename your dev-environment folder…

Your Docker container will still try to mount to the original dev-environment path, even after you rename,
remove, or move the folder DEV-ENVIRONMENT .
After moving your dev-environment folder, you’ll need to delete the old container and start a new container.
You can do so with:

./cs300-run-docker --clean

You should be able to enter a container, and see all of your work now!

End
That'd be all for Part-1 of lab 0. Part-2 will be released during lab time. You must complete all the steps from
this part before coming to the lab.

You might also like