December 25, 2016

Common Docker Commands

Some useful commonly used Docker commands when working on OSX with VirtualBox.

1) This ensures the boot2docker VM is up and running.


docker-machine start default


2) This is the command that needs to be executed once for every new terminal window opened, so as to establish connection with the boot2docker VM(Virtual Machine).

 

 eval “$(docker-machine env defaut)”


3) This command returns the IP address of the 'default' VM running boot2docker


docker-machine ip default


4) Returns a list of VM with boot2docker install and running on VirtualBox.


docker-machine ls

Sample Output:

NAME        ACTIVE   DRIVER       STATE     URL                         SWARM   ERRORS
default     *        virtualbox   Running   tcp://192.168.99.100:2376           



5) Regenerates the TLS certificates needed to communicated with the 'boot2docker' VM.

 

docker-machine regenerate-certs default     /// To regenerate the TLS certs for Docker


6) Lists all available Docker images

 

 docker images


7) Looks the Docker process running with a particular container id.


docker ps -a | grep 


8) Removes a running Docker container

 

docker rm 


9) Removes a particular Docker image


docker rmi  


10) Kills a particular Docker container


docker kill 


 

11) Connects to the Docker container and gives access to the bash shell to execute commands on the container

 

docker exec -i -t  /bin/bash


12) Runs a Docker image and does not automatically terminate the container. Allows an easy way to keep the container running and later connect to the containers shell using "docker exec -it " command.


docker run -d  tail -f /dev/null


13) This is not a Docker command. This utility is part of the virtual box installation. Allows one to power-off a VM running on VirtualBox

 

VBoxManage controlvm  poweroff


14) Again, not a Docker command. A virtual box command to share a directory on the HOST OS (OSX: /Users/esrinivasan/..) with the guest operating system running on VirtualBox. The name of the shared folder is set as "/eks" here.

 


VBoxManage sharedfolder add default --name /eks --hostpath /Users/esrinivasan/develop/learning/Docker/dec-2016/docker-node/docker-volume