This is my cheatsheet for docker. A simple set of commands to manage docker via the terminal.

List running instances: -

docker ps  

List all instances: -

docker ps -a  

Connect to a running instance: -

docker exec -i -t <instance-id/tag-name> bash  

List images: -

docker images  

Remove image: -

docker rmi <image-id>  

Docker tag image: -

docker tag <image-id> <username>/<repo>  

Docker build and tag image: -

docker build --tag <username>/<repo> .  

Docker run image: -

docker run -d -t <image-id/image-name>  

Docker run image, exposing port 80: -

docker run -p 80:80 -d -t <image-id/image-name>  

Docker run image, with environment variable: -

docker run -e env=dev -d -t <image-id/image-name>  

Docker stop all containers: -

docker stop $(docker ps -a -q)  

Docker remove all containers: -

docker rm $(docker ps -a -q)  

Docker build commands - quick reference:-

ADD: Copy a file from the host into the container  
CMD: Set default commands to be executed  
ENTRYPOINT: Set default entrypoint application inside the container  
ENV: Set environment variable (e.g. key = value)  
EXPOSE: Expose a port to outside  
FROM: Set the base image to use  
MAINTAINER: Set the author / owner data of the Dockerfile  
RUN: Run a command and commit the ending result (container) image  
USER: Set the user to run the containers from the image  
VOLUME: Mount a directory from the host to the container  
WORKDIR: Set the directory for the directives of CMD to be executed  

If you are using Mac OSX and not using the quick start terminal, you will probably find a problem with docker not starting. To resolve this try:-

docker-machine start default  
docker-machine regenerate-certs default  
eval "$(docker-machine env default)"  

For when docker decides to play the "Error getting IP address" game

docker-machine rm default  
docker-machine create --driver virtualbox default