Docker

Using the Docker
A short summary of useful docker commands are given in docker cheat sheet.

View existing docker containers
In order to view all existing docker containers run the following command: docker ps -a

Open a shell of a docker
In order to open a new shell of an existing docker, run this command in the server: docker exec -it DOCKER_NAME bash

Exit from a runing container (docker)
In order to to exit press ctr+p+q

Stop a container (docker)
docker stopt DOCKER_NAME

Restart a container (docker)
docker restart DOCKER_NAME

Remove a container (docker)
docker rm DOCKER_NAME This is done only if you want to re-install or its not usefull any more

Open a new docker
Here is a link to YouTube that explain the process by Ziv Aharoni. Please view it before start woring with Docker.

Docker initialization
Pull the desired docker image (you may use DockerHub): The image contains all the relevant installations for our purposes. DockerHub has premade images for all uses (pytorch, tensorflow... etc)

docker pull tensorflow/tensorflow:latest-gpu

Or for pytorch:

docker pull pytorch/pytorch:latest

In order to open a new docker use the following command:

For Permuter1: docker run -it -u $(id -u):$(id -g) --gpus all --restart unless-stopped --mount type=bind,source=/home/$USER/projects/,target=/common_space_docker/ -p 7777:22 -p 5000:5000 -p 5001:5001 -p 5002:5002 --name DOCKER_NAME tensorflow/tensorflow:latest-gpu bash or docker run -it -u $(id -u):$(id -g) --gpus all --restart unless-stopped --mount type=bind,source=/home/$USER/projects/,target=/common_space_docker/ -p 8888:22 -p 6000:6000 -p 6001:6001 -p 6002:6002 --name DOCKER_NAME tensorflow/tensorflow:2.7.1-gpu bash

For Permuter2: sudo nvidia-docker run -it --gpus all --mount type=bind,source=/storage/,target=/common_space_docker/ -p 7777:22 --name DOCKER_NAME pytorch/pytorch:latest bash

For Permuter3: Tensorflow: sudo docker run --gpus all -it --restart unless-stopped --shm-size=1024m --mount type=bind,source=/mnt/,target=/common_space_docker/ -p 8888:22  --name DOCKER_NAME tensorflow/tensorflow:latest-gpu bash

Pytorch: sudo docker run -it --restart unless-stopped --mount type=bind,source=/mnt/,target=/common_space_docker/ -p 7777:22 --name pytorch_docker --gpus all pytorch/pytorch:latest bash

If you want you can limit CPUs (core by core) using: --cpuset-cpus

If you want you can also enlarge shared memory to use workers by passing flag "--shm-size=1024m"

For Permuter4: docker run -u $(id -u):$(id -g) -it --gpus all --restart unless-stopped --mount type=bind,source=/storage/,target=/common_space_docker/ -p 7777:22 -p 5000:5000 -p 5001:5001 -p 5002:5002 --name DOCKER_NAME tensorflow/tensorflow:latest-gpu  bash

Options:
 * bind maps a directory in the server to a directory in the docker. Hence in "source=XXXX" put a new directory for your docker. e.g. "/common_space/new_docker_env". The "target" attribute of mount should not be changed.
 * p maps ports of the server and the docker. For instance "-p 7777:22" maps the port 7777 of the server to port 22 of the docker.
 * name here choose the name of the new docker.

Arguments:
 * docker image path to docker image. e.g "tensorflow/tensorflow:latest-gpu".
 * command to run in the new opened docker. e.g "bash".

Docker restart
In order to reopen a closed docker use the following command docker restart DOCKER_NAME Note that once the docker is restarted, ssh services should be restarted as well using service ssh restart

ssh-server initialization
After installing a new docker you need to enable shell in the docker. Initiate bash shell of the docker: docker exec -u root DOCKER_NAME -it bash

Enable the ssh command, run the following command inside the docker container. apt update && apt install -y openssh-server mkdir /var/run/sshd echo 'USER_NAME:' | chpasswd

The last command changes root password to .

For Permutter1, you need to use the docker with your user name: id docker exec -it DOCKER_NAME bash useradd -r -u USER_ID -m -s /bin/bash -g users USER_NAME echo "USER_NAME:" | chpasswd
 * 1) find it what is your user id from the server itself, this command will print your id
 * 1) open the docker shell with your user (NOT ROOT)
 * 1) Add your username
 * 1) edit your password

The next lines are used to: 1. Permit root login 2. Update something in SFTP protocol to allow authentication.

For Permutter1: docker exec -it -u root DOCKER_NAME bash sed -i '/Subsystem/c\Subsystem     sftp    internal-sftp' /etc/ssh/sshd_config service ssh restart
 * 1) log in to docker from ROOT by:

For Other servers:

sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config sed -i 's/Subsystem.*/Subsystem sftp internal-sftp/g' /etc/ssh/sshd_config service ssh restart

Some containers will have a long startup message, this will cause problems with Pycharm debugger, to erase this just modify /etc/bash.bashrc.

packages installation
apt-get update apt-get install git-core apt install r-base apt install vim less pip install --upgrade pip pip install --upgrade matplotlib scipy tqdm bunch commentjson pandas jupyter statsmodels pip install --upgrade tflearn scikit-learn tensorflow_datasets tensorflow_probability pip install --upgrade torch torchvision

running a jupyter-notebook in the docker
Use the following command inside the docker to start a jupyter server that will be accessible in port. CUDA_VISIBLE_DEVICES=, jupyter notebook --port --no-browser --allow-root --ip 0.0.0.0 Then the web interface is accessible via :

making perm4 3090 GPU's compatible with pytorch
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html