Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Friday, February 12, 2016

Install docker on MAC

I had docker on my ubuntu and I do not remember going through much for installing docker on ubuntu .

But for MAC i had to follow these instructions ( in case anybody is looking for these)

    brew install docker
    brew install boot2docker
    boot2docker up
    boot2docker init
    boot2docker up
    export DOCKER_HOST=tcp://192.168.59.103:2375
    export DOCKER_CERT_PATH=/Users/yours/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1
    boot2docker ip

Monday, November 3, 2014

Docker pitfalls like line endings on windows, dos2unix, permissions e.t.c



Having spent 2-3 weeks on making docker work ( which seemed pretty simple at first but then turned out to be like a peeling onion kind of a problem) ...felt like documenting all the blockers i faced:-

1. yes in my hurry to install docker without reading the official installations noted ..i managed to install the wrong docker ( what are the chances) .. so make sure you follow the right installation steps (https://docs.docker.com/installation/ubuntulinux/) and note they are different for <=ubuntun12.04


2. running docker e.t.c steps were simple to grasp .. but the interesting stuff came in when i discovered Dockerfile...i assumed it should look like the install script i have (that is called from the vagrantfile i have ..since currently i was using vagrant for my app) .....That was a big mistake. It took me sometime to learn the concept of "loosing context" and "new image being formed after every RUN in dockefile" ...so make sure you understand that after every RUN command .. the next command does not know anything about your state

3. in windows you will run into this issue  http://www.rsync.net/resources/howto/windows_rsync.html.. Use rsync .
and when you user rsync you might run into this issue
https://github.com/mitchellh/vagrant/issues/3230  ....which you can fix by modifying a file in vagrant (yucks!)
 just edit C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.5.1\plugins\synced_folders\rsync\helper.rb and add hostpath = "/cygdrive" + hostpath to line 74. It's a terrible solution but quick and simple.

4. If you manage to start the docker container on windows the next thing you will notice is .. none of your scripts are running. The reason is line endings on windows!!! dos2unix can help and rescue here   .. just go int the container and do dos2unix *.sh and it shall fix it. For some reason i tried to do the samething in my dockefile but it hung up ..everytime i build the container ( and this is when i gave up on my quest to make it run on windows)

5.  if you are running any scripts from dockerfile .. make sure your have permissions set correctly before you run docker or set  it within the dockerfile

6) Other great lesson i learned was ( thanks to my co-worker) ..to start with baseimages (http://phusion.github.io/baseimage-docker/) ...for a simpler and reliable(preloaded) start.

7) one more easily overlooked fact .. is you have to apt-get update before installing anything  on fresh  base image



8) ..i feel at this point that  ran into more things/notes/blockers during last 2-3 weeks .. but can not recall them right now .. will add them later if i can recall them .. but the feeling i got my the end of it was .. docker is not very intuitive ...it harder to debug and understand .. than it is to learn docker.

Docker notes (cheatsheet)

#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q) 

 
 # Delete all images
docker rmi $(docker images -q)
docker rmi $(docker images | grep "^<none>" | awk "{print $3}") 
 
#build docker image (do all the installs preprations here)
sudo docker build . 
 
#run interactively 
docker run -t -i -rm -v /home/njain/office/buzz/:/opt/buzz/  4185a2a31f87(image name) 
 
#attach volume and run interactively 
docker run -t -i -rm -v /home/njain/office/buzz/:/opt/buzz/  4185a2a31f87(image name)
 
#commit 
docker commit 14c9b7581273  username/pwd
 
#to run docker without sudo 
sudo chmod o+rw /var/run/docker.sock 
 
 
some day to day scripts useful for every docker project
 

~/office/buzz (testdocker) > cat dockscripts/dockbuild
docker build -t buzz .


~/office/buzz (testdocker) > cat dockscripts/deploy
docker run -d -p 5672:5672 -p 15672:15672 -p 5000:5000  buzz > pid


~/office/buzz (testdocker) > cat dockscripts/shell
docker run --rm -t -i -p 5672:5672 -p 15672:15672 -p 5000:5000  buzz /bin/bash


~/office/buzz (testdocker) > cat dockscripts/destroy
docker rm -f $(cat pid)


rm pid~/office/buzz (testdocker) > cat dockscripts/cleanup
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -a -q)