Monday, November 3, 2014

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)



No comments:

Post a Comment