Here are some common Docker and Docker-Machine commands. You only need Docker Machine if you are on OSX.

Docker Machine

Create the default machine:

docker-machine create --driver virtualbox default

The default machine is created at:

~/.docker/machine/machines/default

List machines:

docker-machine ls

Show environment properties of machine:

docker-machine env machine_name

Shows ip of machine:

docker machine ip machine_name

Start a machine:

docker-machine start machine_name

SSH into a machine:

docker-machine ssh machine_name

Show detailed information about a machine:

docker-machine inspect machine_name

Docker

Create a terminal bound to machine. You have to do this before you run any docker commands:

eval "$(docker-machine env machine_name)"

Create a tagged image from a Dockerfile:

docker build -t repository/image:tag .

Run a container as a daemon:

docker run -d ...

Run a container exposing ports:

docker run -p external_port:internal_port ...

Run a contain exposing random ports:

docker run -P (maps internal port to random external port) ...

Run a container with a mapped volume:

docker run -v host_path:container_path ...

Run a container with environment arguments:

docker run -e ENV_NAME_1=value1 -e ENV_NAME_2=value2 ...

Run a container with mapped ports, volumns and an enviroment variable:

docker run --name some-mysql \
           -p 3306:3306 \
           -v /mydata:/var/lib/mysql \
           -e MYSQL_ROOT_PASSWORD=some_secret \
           -d mysql

Connect to a running container:

docker exec -it container_name bash

List Docker processes:

docker ps

List last run container:

docker ps -l

List all containers running or otherwise:

docker ps -a

List Docker images:

docker images

Start a Docker container:

docker start container

Stop a Docker container:

docker stop container

Restart a stopped container:

docker restart container

Remove a Docker container:

docker rm container

Show logs of a container:

docker logs -f container

Show port mappings for a container:

docker port container