Using Docker
Common commands I use:
boot2docker up: This launches the boot2docker daemon on osx. After running I then have to copy/paste theexportstatements printed by this command to set up ports. An alternative is$(boot2docker shellinit), which will do the copy/pase ofexports for me.docker ps -a: lists all containersdocker rm $(docker ps -a -q): remove all containers (running or not)docker images: list local imagesdocker run IMAGE_NAME: runs the docker image. NOTE: often not useful because you also need todocker run -it IMAGE_NAME COMMAND: runsCOMMANDinside the imageIMAGE_NAMEand leaves you in terminal/interactive mode. This is most often what I use. Often the command is/bin/bashto just drop me into the terminaldocker run -it -v LOCAL_PATH:REMOTE_PATH IMAGE_NAME COMMAND: runsCOMMAND: like the above, but maps a local file/folder atLOCAL_PATHto the image’s filesystem atREMOTE_PATHdocker stop $(docker ps -a -q): stops all processesdocker build -t USERNAME/IMAGE_NAME .: Use the dockerfile in the current directory to build an image. Tag the image with theUSERNAMEandIMAGE_NAMEdocker search NAME: searches dockerhub for images containingNAMEdocker pull USERNAME/IMAGE_NAME: Pulls imageUSERNAME/IMAGE_NAMEfrom dockerhubdocker history USERNAME/IMAGE_NAME: shows the history of an imagedocker rmi IMAGE_ID1 IMAGE_ID2: remove images by ID. Can list multiple images at oncedocker stop IMAGE_ID: stops an imagedocker run -p IMAGE_PORT:LOCAL_PORT ....: runs an image (with other args and image name omitted) and maps portIMAGE_PORTon the image toLOCAL_PORTon my machine.
Working on ubuntu
I didn’t like having to use sudo to use docker commands. This stackoverflow Q/A has a workaround that worked for me