Hguimaraes random tech notes

Setup a Kaggle env using Docker

tl;dr: Despite being well documented on Kaggle’s blog, this is a small guide to install docker and the kaggle\python image on a computer with Ubuntu 16.04

Install Docker and Docker-Machine

To install docker on your Ubuntu 16.04 system:

$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce

To ensure that docker was sucessfully instaled:

$ sudo docker run hello-world

If everything was installed right, this should print a “Hello from Docker” message. After the installation, we will do some steps to manage docker as non-root user.

$ sudo groupadd docker
$ sudo usermod -aG docker $USER

Logout and Login back to the group change take effect. And to ensure that everything is fine, run the hello-world again, but without sudo:

$ docker run hello-world

Pull the kaggle-python

$ docker pull kaggle/python

Note: This may take a while

Setup the enviroment

Add the following lines to your ~/.bashrc

kpython(){
  docker run -v $PWD:/tmp/working -w=/tmp/working --rm -it kaggle/python python "$@"  
}
ikpython() {
  docker run -v $PWD:/tmp/working -w=/tmp/working --rm -it kaggle/python ipython
}
kjupyter() {
  docker run -v $PWD:/tmp/working -w=/tmp/working -p 8888:8888 --rm -it kaggle/python jupyter notebook --no-browser --ip="0.0.0.0" --notebook-dir=/tmp/working --allow-root
}

Notes on how to use

And then we are ready to go. We can use kpython as replacement for python and run kjupyter to start a new notebook with all the tools from Kaggle installed

comments powered by Disqus