# Deploying a docker container running jupyter notebooks on a remote server. The standard way : The standard way is to write everything in a DockerFile, build an image using this file and deploy the image. But for someone just starting to learn docker, this is really difficult. The dumb way : As a beginner its better to one by one install and modify things and commit the changes ourselves. Once someone becomes comfortable with this, they can directly write DockerFile and directly make images with everything setup. Create a local docker image, modify it, then deploy on a remote machine as a docker container and access jupyter notebook running inside this container. ### Create an image from a base image: Save the following in a file named DockerFile ``` FROM continuumio/miniconda3 RUN conda install jupyter ``` This pulls an image from dockerhub that has conda install in some linux distribution. Then run following command from same directory: ``` docker build my_image . ``` Now our basic image is ready. We run it as a container, inspect it interactively, make some changes and then commit those changes. ### Run the image and modify it - Open the image (run container) in interactive mode : docker run -it my_image /bin/bash - Now make changes to the image, it can be pulling a git repo or copying some files. - Change jupyter config file to allow all connections - Exit the container and commit changes using : - Save the image file : sudo docker save -o /home/prakhar test_image ### Setup Remote Machine 1. Install docker on remote machine. 2. copy image we just created 3. copy any data 4. Load the copied image to sudo docker load --input test_image ### Run container on Remote Machine ssh to Remote Machine goto root service docker status/start Create two tmux screens, one for docker, one for host Window 1 :Start Container : docker run -v /path/to/media -it -p 8888:8888 my_image /bin/bash Window 2 : Monitor container jupyter notebook --ip 0.0.0.0 --allow-root ### Access Notebook - Access notebook at ip-of-remote-machine:8888 - Use the tocken printed in terminal to authenticate ### Close container and exit 1. Close jupyter. 2. exit container. 3. docker commit rwerwe first_image 3. docker remove rm image_ID 4. service docker stop ### DOCKER COMMANDS 1. status : service docker status 2. save : sudo docker save -o /home/prakhar test_image 3. load : sudo docker load --input test_image 4. remove all containers : sudo docker rm $(sudo docker ps -a -q)