The Docker container-based virtualization service lets you run a minimal CS 61 environment, including a virtual Linux host, on a Mac OS X or Windows host, without the overhead of a full virtual machine solution like VMware Workstation, VMware Fusion, or VirtualBox.
It should be possible to do all CS 61 problem sets on CS 61 Docker.
Advantages of Docker:
- Docker can start and stop virtual machines incredibly quickly.
- Docker-based virtual machines are leaner and take less space on your machine.
- With Docker, you can easily edit your code in your home environment, but compile and run it on a Linux host.
Disadvantages of Docker:
- Docker does not offer a full graphical environment. You will need to run all CS61 programs exclusively in the terminal.
- Docker technology is less user-friendly than virtual machines. You’ll have to type weird commands.
- You won’t get the fun, different feeling of a full Linux desktop.
To prepare to build your Docker environment:
-
Download and install Docker.
-
Clone a copy of the cs61-lectures repository.
-
Change into the
cs61-lectures/docker
directory.
To build your Docker environment, run this command. It will take a couple minutes. You’ll want to re-run this command every time the Docker image changes, but later runs should be much faster since they’ll take advantage of your previous work.
$ docker build -t cs61:latest -f Dockerfile .
Our handout repositories, including cs61-lectures
and cs61-psets
, contain
a cs61-run-docker
script that provides good arguments and boots Docker into
a view of the current directory. We will update this script throughout the
term.
For example:
$ cd ~/cs61-lectures/datarep1
$ echo Hello, Mac OS X
Hello, Mac OS X
$ ls
GNUmakefile NOTES.md README.md add add.cc addf.cc
$ ../cs61-run-docker
cs61-user@a47f05ea5085:~/cs61-lectures/datarep1$ echo Hello, Linux
Hello, Linux
cs61-user@a47f05ea5085:~/cs61-lectures/datarep1$ ls
add add.cc addf.cc GNUmakefile NOTES.md README.md
cs61-user@a47f05ea5085:~/cs61-lectures/datarep1$ exit
exit
$
The script plonks you into a virtual machine! A prompt like
cs61-user@a47f05ea5085:~$
means that your terminal is connected to the VM.
You can execute any commands you want. To escape from the VM, type Control-D
or run the exit
command.
The script assumes your Docker container is named cs61:latest
, as it was above.
If you don’t want to use the script, use a command like the following.
$ docker run -it --rm -v ~/cs61-lectures:/home/cs61-user/cs61-lectures cs61:latest
Explanation:
docker run
tells Docker to start a new virtual machine.-it
says Docker should run interactively (-i
) using a terminal (-t
).--rm
says Docker should remove the virtual machine when it is done.-v LOCALDIR:LINUXDUR
says Docker should share a directory between your host and the Docker virtual machine. Here, I’ve asked for the host’s~/cs61-lectures
directory to be mapped inside the virtual machine onto the/home/cs61-user/cs61-lectures
directory, which is the virtual machine user’s~/cs61-lectures
directory.cs61:latest
names the Docker image to run (namely, the one you built).
Here’s an example session:
$ docker run -it --rm -v ~/cs61-lectures:/home/cs61-user/cs61-lectures cs61:latest
cs61-user@a15e6c4c8dbe:~$ ls
cs61-lectures
cs61-user@a15e6c4c8dbe:~$ echo "Hello, world"
Hello, world
cs61-user@a15e6c4c8dbe:~$ cs61-docker-version
1
cs61-user@a15e6c4c8dbe:~$ exit
exit
$