Wednesday, November 15, 2017

Docker commands cheat sheet


Welcome to world of Docker. Docker is such a blessing for DevOps folks and processes. We still remember days when world is amazed by virtual machines. Oh, I can spin off multiple virtual OSes running on host windows. Virtual machines indeed solved some of the problems. However, they're clunky, heavy in size.

Docker took us to another granular level of containers & images much thinner then virtual OSes, layered images further reducing the size of images and making deployments easy piece of cake. You can further optimize cost savings with Docker containers. Totally isolated, bootstrapped environment which can run on any docker host with any constraints opens up a whole lot of possibilities.

We're impressed with Docker. We integrated Docker containers into our workflows. Docker file is an amazing piece of art. Few concise commands in a text file can initialize, build and run a mission critical app in few seconds.

Let's grasp some useful docker commands. Of course, this list is very small. We'll keep adding as we learn more and more

DOCKER COMMAND
DESCRIPTION
Docker PS
list of running containers
DOCKER RM [ID]
removes container with specific ID
DOCKER Images ls
list of all containers
DOCKER STOP [ID]
stops container
LESS PATH
UNIX command to open a longer file
docker build -t api -f testapp/Dockerfile . &&  docker run -it -p 9000:9000 api
Builds a container using specific docker file and runs containers on a specific port
docker run -it -p 9000:9000 --entrypoint bash api
Runs a shell in a container that is running
CAT  PATH – opens a file in terminal

Q – to exit the file