Thursday, November 23, 2017

Cleaning up Docker disk space


Docker seems to eat disk space and leave a lot of left overs around. Here are some resources to fix that.

Docker image prune (the new standard fix)

docker image prune

https://docs.docker.com/config/pruning/
https://docs.docker.com/engine/reference/commandline/image_prune/
https://gist.github.com/anildigital/862675ec1b7bccabc311


General Info
https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes

https://stackoverflow.com/questions/17665283/how-does-one-remove-an-image-in-docker


Is the /var/lib/docker/ folder large?
sudo du -sh /var/lib/docker/

If it's large, may need to zap it (careful with this one!):
Ref: https://stackoverflow.com/questions/45798076/how-to-clean-up-docker

$ sudo su
# service docker stop
# cd /var/lib/docker
# rm -rf *
# service docker start

For more info about this folder see: https://stackoverflow.com/questions/19234831/where-are-docker-images-stored-on-the-host-machine


And also......try removing dangling images

https://forums.docker.com/t/how-to-remove-none-images-after-building/7050/3

List dangling:
docker images -f "dangling=true" -q

Delete dangling:
docker rmi $(docker images -f "dangling=true" -q)

Force delete dangling:
docker rmi -f $(docker images -f "dangling=true" -q)


Wednesday, September 13, 2017

Rsync Broken Pipe Error with SSH

Try adding these settings:

KeepAlive yes
ServerAliveInterval 20
ServerAliveCountMax 6

to your /etc/ssh/ssh_config or ~/.ssh/config file.

To solve Broken Pipe errors.

Reference: https://unix.stackexchange.com/questions/68775/rsync-timed-out

Thursday, August 24, 2017

Installing Docker on an Ubuntu AWS EC2 machine

sudo apt-get update

# Install packages to allow apt to use a repository over HTTPS:
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

# For "sudo: unable to resolve host ip-x-x-x-x" errors, follow the following link to set "DNS Hostnames" to True:
# http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-dns.html#vpc-dns-updating
sudo true

# Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify that the key fingerprint is 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88.
sudo apt-key fingerprint 0EBFCD88

# Use the following command to set up the stable repository.
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# Install the latest version of Docker CE
sudo apt-get update
sudo apt-get install docker-ce
sudo docker run hello-world

# Ref: https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#install-using-the-repository

Wednesday, August 23, 2017

Set up RVM, Ruby, Gem & Jykll to serve a username.github.io blog

Here are the steps I took to set up RVM, Ruby, Gem & Jykll to serve a username.github.io blog on OSX:

# Install RVM (Ruby version manager) 
# Also read: http://rvm.io/rvm/install and check the script before running
curl -sSL https://get.rvm.io | bash -s stable --ruby

# Install Ruby (replace x.y.z with latest stable version of ruby)
rvm install x.y.z
rvm docs generate-ri
rvm use x.y.z --default

# Check other requirements are available for jekyll and install if missing
gem --version
gcc --version
make --version

# Install jekyll
gem install jekyll

# Install bundler and get all dependencies
gem install bundler
bundle install

# Clone an existing jekyll template, this one from BlackrockDigital is nice
git clone https://github.com/BlackrockDigital/startbootstrap-clean-blog-jekyll.git
cd startbootstrap-clean-blog-jekyll
bundle exec jekyll serve

# Periodically update Jekyll to match the GitHub Pages server
bundle update github-pages

Reference:
https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/
http://jekyllrb.com/docs/installation/
https://jekyllrb.com/docs/posts/
https://github.com/planetjekyll/awesome-jekyll-editors


Wednesday, March 29, 2017

Running PaCAL on OSX with conda

PaCAL is a great library for performing arithmetic on probabilistic random variables just like you do with ordinary program variables. Here is a more detailed paper on PaCAL.

There are a couple of gotchas setting it up on OSX with conda:

  • Requires Python 2.7.x (3.x not supported as of March 2017)
  • Required dependencies: numpy matplotlib sympy scipy
  • Workaround for "RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework".

Here are the steps to set up PaCAL under a conda environment on OSX:

$ conda create -n pacal python=2.7
$ source activate pacal

(pacal) $ pip install numpy matplotlib sympy scipy
(pacal) $ pip install pacal

(pacal) $ python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
>>>
>>> # This TkAgg bit is to prevent the OSX 'Python is not installed as a framework' error.
>>> import matplotlib as mpl
>>> mpl.use('TkAgg')
>>>
>>> from pacal import *
Compiled interpolation routine not available
Compiled sparse grid routine not available
>>> dL = UniformDistr(1,3)
>>> L0 = UniformDistr(9,11)
>>> dT = NormalDistr(1,1)
>>> K = dL / (L0 * dT)
>>> K.plot()
>>> show()



Wednesday, February 15, 2017

Conda create environment commands


Conda create environment commands - super easy but nice to have as a reference:

# Python 2.7
$ conda create -n myenvname python=2.7 # Python 3.4 $ conda create -n myenvname python=3.4 # Python 3.x latest $ conda create -n myenvname python=3

$ source activate myenvname

More info: https://conda.io/docs/using/envs.html

If you then have a requirements.txt file, you can install the listed packages with:
conda install --yes --file requirements.txt

If you want to reproduce an existing conda environment on another machine, you can get a snapshot with:
conda env export > freeze.yml

which can then be restored via:
conda env create -f freeze.yml

Saturday, February 11, 2017

Install xgboost on OSX with full OpenMP support in an anaconda virtualenv

The default gcc with OSX doesn't support OpenMP which enables xgboost to utilise multiple cores when training.

These steps show how to install gcc-6 with OpenMP support and build xgboost to support multiple cores and contain the python setup in an Anaconda virtualenv.

Install/update brew to support installing gcc-6:
See http://brew.sh/

Install gcc-6 with OpenMP support:
brew install gcc --without-multilib
Run brew doctor to ensure gcc-6 and g++-6 are linked correctly

Get latest xgboost from github:
git clone --recursive https://github.com/dmlc/xgboost

Build xgboost with gcc-6:
See https://xgboost.readthedocs.io/en/latest/build.html
cd xgboost; cp make/config.mk ./config.mk;
Ensure that the newly installed gcc-6 compliers are correct in config.mk (e.g. export CC = gcc-6; export CXX = g++-6)
make -j4
(This can take around 30 mins to build)

Create anaconda xgboost virtualenv:
conda create -n xgboost python=3.5
source activate xgboost

Install prerequisite numpy package in xgboost env:
conda install numpy

Set up xgboost for python xgboost virtualenv without sudo:
Ensure you are in the xgboost virtualenv (e.g. which python -> /Users/<user>/anaconda/envs/xgboost/bin/python)
cd <git_clone_location>/xgboost/python-package
python setup.py install
(This can take around 10 mins)

Test xgboost:
open a python session
Try import xgboost as xgb

Finally, set up Jupyter notebook:
If you want to access xgboost via Kernel > Change Kernel in Jupyter:
conda install jupyter

Helpful reference:
https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_XGBoost_on_Mac_OSX?lang=en