Computer Science Docker

Do not install Docker without reading this, even on a computer that you manage yourself.

What is Docker?

Docker is a system for creating and using "containers." A container is somewhat like a virtual machine, except that it doesn't have its own kernel. There are two main uses:

Do you need Docker or should you use Singularity?

Docker images are often used to package software for AI and data analysis. If you find a docker image that has software you want to use, we suggest that you use the program singularity to run the docker image. Singularity is easier to use than Docker, and gives you access to your normal files within the container. It can run most Docker images.

However if you are trying to create a new Docker image, rather than just run an existing one, you'll need the actual Docker software. You'll also need the actual Docker if you need to run a Docker image that has servers such as a web server in it.

This page is designed to tell you how to install Docker on Computer Science systems.

If you can become root

This section is for people who run their own Linux systems. If you're using a system that we run, such as the ilab systems, please see the next section.

If you can do su or sudo, you can do a normal Docker installation. You can install it using apt (Ubuntu) or yum (Centos), or get the most recent release directy from the Docker web page. But there's one thing you must do first .

If you simply install Docker without doing anything else, your system may lose access to the network. To prevent this, before installing Docker create the file /etc/docker/daemon.json . It should contain the following:

{
  "bip": "192.168.100.2/24",
  "mtu": 1500
}
This will cause Docker to use a network that doesn't conflict with any of ours.

One other warning: Docker images and volumes must be on a local disk. Docker doesn't work with NFS, i.e. file systems mounted from file servers. On most systens, your home directory is on a file server. So make sure you put Docker files on /usr, /var, /freespace, etc.

If you can't become root -- i.e. you're a normal user

Until recenly, Docker could only be used by people who could do su or sudo. However the most recent release can be used by normal users. Here is a page that describes that: Run the Docker daemon as a non-root user .

However there are some things you must do before you try this out on one of the systems we run. The example below shows all of these things.

Installing and Setting up Docker as a User without root Access

Here's an example of installing Docker as a user. This one was done on ilabu2.cs.rutgers.edu

df -h /freespace
# 14G free. Marginal. Consider a different systems
# WARNING: we may remove files from /freespace between semesters

# make a directory for docker on a local file system
mkdir -p /freespace/local/$USER/docker

# link it to where docker expects it to be
mkdir -p ~/.local/share
ln -s /freespace/local/$USER/docker ~/.local/share
sudo /usr/libexec/addsubusers.py
# if the previous command fails, contact help@cs.rutgers.edu
# the system you're usin isn't properly set up

# create the network config file
mkdir -p ~/.config/docker
cp /etc/docker/daemon.json ~/.config/docker/daemon.json

# now do the installation as documented on the web page
# make sure we start in the home directory
cd
curl -fsSL https://get.docker.com/rootless | sh

### up to here should only be done once
### below here has to be done every time you login

# the curl command will print two export commands. do them
export PATH="$HOME/bin:$PATH"
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock

# put those two export commands in .bashrc if you are
# going to do this a lot

# you must do the follow command again every time
# you login.
systemctl --user start docker
# verify that docker started with no errors
systemctl --user status docker

# now try it. fetch a copy of alpine and run it 
# To give docker access to /freespace/local 
# add -v hostpath/dockerpath parameter.
# You can add multiple -v options for more disks.
# I've picked alpine because it's a Linux system, but it's only 5 MB
docker run -v /freespace/local:/freespace/local -it alpine  
# you'll get a prompt like / #
# try something that uses the network
apk update

# exit back to your normal shell
 exit

I recommend using only one system for Docker, or at least one system per home directory. (E.g., if you're part of CBIM, you have a home directory on /ilab/users and a CBIM directory on /dresden/users. You could install Docker on one system using ilab and one CBIM system.)