Using Docker
Common commands I use:
boot2docker up
: This launches the boot2docker daemon on osx. After running I then have to copy/paste theexport
statements printed by this command to set up ports. An alternative is$(boot2docker shellinit)
, which will do the copy/pase ofexport
s 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
: runsCOMMAND
inside the imageIMAGE_NAME
and leaves you in terminal/interactive mode. This is most often what I use. Often the command is/bin/bash
to 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_PATH
to the image’s filesystem atREMOTE_PATH
docker 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 theUSERNAME
andIMAGE_NAME
docker search NAME
: searches dockerhub for images containingNAME
docker pull USERNAME/IMAGE_NAME
: Pulls imageUSERNAME/IMAGE_NAME
from 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_PORT
on the image toLOCAL_PORT
on 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