# Dockerfile examples

## Dockerfile example by Josh Gordon

Ref: <https://hub.docker.com/r/jbgordon/recipes/>

Ref: <https://www.youtube.com/watch?v=tNa99PG8hR8&list=PLOU2XLYxmsIIuiBfYad6rFYQU_jL2ryal&index=6>

```
FROM gcr.io/tensorflow/tensorflow:latest-devel

RUN pip install --upgrade pip
RUN apt-get update
RUN apt-get install -y graphviz libgraphviz-dev pkg-config
RUN pip install pygraphviz
RUN apt-get install -y python-scipy
RUN pip install pydot
RUN pip install sklearn
```

## To remove mysql from docker

```
 apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5
 rm -rf /etc/mysql /var/lib/mysql
 apt-get autoremove
 apt-get autoclean
```

## Dockerfile example

### *installing vim, nodejs, mysql-server, graphviz, cython, pandas, Pillow etc..*

```
FROM gcr.io/tensorflow/tensorflow:latest-devel
#
RUN echo "========================================"
RUN echo "Updating and upgrading"
RUN echo "========================================"
RUN sudo apt-get -y update
RUN sudo apt-get -y upgrade
#
RUN echo "========================================"
RUN echo "Installing vim"
RUN echo "========================================"
RUN sudo apt-get install -y vim
#
RUN echo "========================================"
RUN echo "Installing nodejs"
RUN echo "========================================"
RUN sudo curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
RUN sudo apt-get install -y nodejs
#
RUN echo "========================================"
RUN echo "Installing mysql-server"
RUN echo "========================================"
RUN sudo apt-get install -y mysql-server-5.6
RUN sudo cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
RUN sudo mysql_install_db
RUN sudo service mysql start
#
RUN echo "========================================"
RUN echo "Installing python packages"
RUN echo "========================================"
RUN sudo apt-get install -y cython
RUN sudo apt-get install -y python-pandas
RUN sudo apt-get install -y python-cairosvg
RUN sudo apt-get install -y python-pydot
RUN sudo apt-get install -y python-pygraphviz
RUN sudo pip install --upgrade pip
RUN sudo pip install pydotplus
RUN sudo pip install graphviz
RUN sudo pip install Pillow
RUN sudo pip install keras
#RUN cd /tensorflow
#RUN git pull
#RUN cd /
#RUN ./run_jupyter.sh
RUN echo "========================================"
RUN echo "Executing cmd bash"
RUN echo "========================================"
CMD ["/bin/bash"]
```

## To build a custom docker image based on the Dockerfile

```
> cd <to the directory where you have created the Dockerfile>
> docker build -t custom-tf-docker-image .

To build in Amazon AWS
first switch to root user: 
> sudo su

Then install docker
> apt-get update
> apt-get upgrade
> apt install docker.io (doubt)

Replace all 'sudo' in the Dockerfile. In AWS, somehow from the user ubuntu, the sudo RUN commands
did not work. So did the workaround as mentioned above

I had to comment out the sudo part in the nodejs installation and installation of mysql-server-5.6

Then use the build command: 
> docker build -t custom-tf-docker-image .

The run docker container in AWS as:
> docker run -p 8888:8888 -p 6006:6006 --name tensorflow-agshift -it -v /home/ubuntu/MLDL/STRAWBERRY_ML_TEST/tf_files:/tf_files custom-tf-docker-image

If tf_files is in /home/ubuntu then do
> docker run -p 8888:8888 -p 6006:6006 --name tensorflow-agshift -it -v /home/ubuntu/tf_files:/tf_files custom-tf-docker-image

To start jupyter:
> cd /
> nohup ./run_jupyter.sh &

To run jupyter in the background:
==================================
cd /
nohup ./run_jupyter.sh > tf_files/nohup.out 2>&1 < /dev/null &

If an error pops out saying that "running as root is not recommended" then do the following
> nohup ./run_jupyter.sh --allow-root > tf_files/nohup.out 2>&1 < /dev/null &


Using nohup and launching in the background will enable us to re-use the same AWS session

=======
Note:
=======
If the web browser does not connect to jupyter session, make sure that the EC2 instance 
has the correct 'security group' with the ports opened up - like launch-wizard-3
```
