Docker

Using the Docker
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

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

For Permuter1: sudo docker run -it --gpus all --mount type=bind,source=/common_space/,target=/common_space_docker/ -p 7777:22 --name DOCKER_NAME gcr.io/tensorflow/tensorflow:latest-gpu-py3 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: sudo nvidia-docker run --gpus all -it --restart unless-stopped --mount type=bind,source=/storage/,target=/common_space_docker/ -p 7777:22  --name DOCKER_NAME tensorflow/tensorflow:latest-gpu-py3  bash

For Permuter4:
 * need to fill in ********

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 "gcr.io/tensorflow/tensorflow:latest-gpu-py3".
 * 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
Initiate bash shell of the docker: docker exec -it DOCKER_NAME 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 'root:' | chpasswd

The last command changes root password to 123456. sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config sed -i 's+Subsystem     sftp    /usr/.*+Subsystem sftp internal-sftp+' /etc/ssh/sshd_config sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd echo "export VISIBLE=now" >> /etc/profile 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 install vim pip install --upgrade pip pip install --upgrade tensorflow tflearn matplotlib keras torch torchvision scikit-learn scipy tqdm tensorflow_datasets bunch tensorflow_probability